Skip to content

Instantly share code, notes, and snippets.

@quanon
Last active May 15, 2017 13:55
Show Gist options
  • Select an option

  • Save quanon/c7b4f588d9c3d955f65b13eeb206ac29 to your computer and use it in GitHub Desktop.

Select an option

Save quanon/c7b4f588d9c3d955f65b13eeb206ac29 to your computer and use it in GitHub Desktop.
Enumerator::Lazy
[1] pry(main)> (1..10).map { |i| (i ** 2).tap(&method(:p)) }.map { |i| i.to_s.tap(&method(:p)) }
1
4
9
16
25
36
49
64
81
100
"1"
"4"
"9"
"16"
"25"
"36"
"49"
"64"
"81"
"100"
=> ["1", "4", "9", "16", "25", "36", "49", "64", "81", "100"]
[2] pry(main)> (1..10).lazy.map { |i| (i ** 2).tap(&method(:p)) }.map { |i| i.to_s.tap(&method(:p)) }.force
1
"1"
4
"4"
9
"9"
16
"16"
25
"25"
36
"36"
49
"49"
64
"64"
81
"81"
100
"100"
=> ["1", "4", "9", "16", "25", "36", "49", "64", "81", "100"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment