Upgrade to Pro — share decks privately, control downloads, hide ads and more …

怠惰なRubyistへの道 - Enumerator::Lazy の使いかた

怠惰なRubyistへの道 - Enumerator::Lazy の使いかた

みなとRuby会議01での発表「怠惰なRubyistへの道 - Enumerator::Lazy の使いかた」の発表資料を配布用に編集したものです。

nagachika

June 02, 2012
Tweet

More Decks by nagachika

Other Decks in Technology

Transcript

  1. UP@FOVN FOVN@GPS &OVNFSBUPSͷ࡞Γ͔ͨ w &OVNFSBUPSOFX PCK NFUIPEFBDI  BSHT w

    PCKUP@FOVN NFUIPEFBDI  BSHT w PCKFOVN@GPS NFUIPEFBDI  BSHT w &OVNFSBUPSOFX\]Z]^ ˢ͜Ε͚ͩͪΐͬͱಛघ 23
  2. &OVNFSBUPS-B[Z > Enumerator::Lazy.instance_methods(false) map collect flat_map collect_concat select find_all reject

    grep zip take take_while drop drop_wihle cycle lazy force [ruby 2.0.0dev (2012-05-30 trunk 35844)] 37
  3. "-B[Z%FNP >> l = (0..5).lazy => <Enumerator::Lazy: 0..5> >> l_map

    = l.map{|i| p i; i * 2 } => <Enumerator::Lazy: #<Enumerator::Lazy: 0..5>:map> # ͜ͷ࣌఺Ͱ͸·ͩϒϩοΫͷ಺༰͸࣮ߦ͞Ε͍ͯͳ͍! >> l_map.force 0 1 2 3 4 5 => [0, 2, 4, 6, 8, 10] # force ΛݺͿͱ࣮ߦ͞ΕΔ 39
  4. 1JUGBMMPG &OVNFSBUPS  NBQ TFMFDUͷΑ͏ʹϒϩοΫͷ໭Γ஋ Λར༻͢ΔϝιουΛ֎෦ΠςϨʔλԽ͠ ͯ΋ҙຯ͕ͳ͍ F  TFMFDU

    FOFYU FOFYU FOFYU FOFYU ˢTFMFDUͷҙຯ͕ͳ͘ͳ͍ͬͯΔ 43
  5. -B[Z$IBJO%FNP >> (0..4).lazy.select{|i| p “select:#{i}”; i.event? }.map{|i| p “map:#{i}”; i

    * 2 }.force “select:0” “map:0” “select:1” “select:2” “map:2” “select:3” “select:4” “map:4” => [0, 4, 8] 58