Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-enum-lazy
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-enum-lazy/mrbgem.rake
r321 r331 2 2 spec.license = 'MIT' 3 3 spec.author = 'mruby developers' 4 spec.summary = 'Enumera ble::Lazy class'4 spec.summary = 'Enumerator::Lazy class' 5 5 spec.add_dependency('mruby-enumerator', :core => 'mruby-enumerator') 6 6 spec.add_dependency('mruby-enum-ext', :core => 'mruby-enum-ext') -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-enum-lazy/mrblib/lazy.rb
r321 r331 3 3 # = Enumerable#lazy implementation 4 4 # 5 # Enumerable#lazy returns an instance of Enumera ble::Lazy.5 # Enumerable#lazy returns an instance of Enumerator::Lazy. 6 6 # You can use it just like as normal Enumerable object, 7 7 # except these methods act as 'lazy': … … 17 17 # - zip 18 18 def lazy 19 Lazy.new(self)19 Enumerator::Lazy.new(self) 20 20 end 21 end 21 22 23 class Enumerator 22 24 # == Acknowledgements 23 25 # … … 40 42 } 41 43 end 44 45 def to_enum(meth=:each, *args, &block) 46 lz = Lazy.new(self, &block) 47 lz.obj = self 48 lz.meth = meth 49 lz.args = args 50 lz 51 end 52 alias enum_for to_enum 42 53 43 54 def map(&block) -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-enum-lazy/test/lazy.rb
r321 r331 1 assert("Enumera ble::Lazy") do1 assert("Enumerator::Lazy") do 2 2 a = [1, 2] 3 assert_equal Enumera ble::Lazy, a.lazy.class3 assert_equal Enumerator::Lazy, a.lazy.class 4 4 end 5 5 6 assert("Enumera ble::Lazy laziness") do6 assert("Enumerator::Lazy laziness") do 7 7 a = Object.new 8 8 def a.each … … 41 41 end 42 42 43 assert("Enumerable::Lazy#zip with cycle") do 43 assert("Enumrator::Lazy#to_enum") do 44 lazy_enum = (0..Float::INFINITY).lazy.to_enum(:each_slice, 2) 45 assert_kind_of Enumerator::Lazy, lazy_enum 46 assert_equal [0*1, 2*3, 4*5, 6*7], lazy_enum.map { |a| a.first * a.last }.first(4) 47 end 48 49 assert("Enumerator::Lazy#zip with cycle") do 44 50 e1 = [1, 2, 3].cycle 45 51 e2 = [:a, :b].cycle
Note:
See TracChangeset
for help on using the changeset viewer.