README.md: methodphitamine & makros. VERSION 0.1.3
This commit is contained in:
parent
ed649d3801
commit
11128ea131
43
README.md
43
README.md
|
@ -48,6 +48,49 @@ Functional#p prints everything to stdout.
|
|||
select {|i| i%5 == 2 }.
|
||||
to_a
|
||||
|
||||
Thanks to `Symbol#to_proc`:
|
||||
|
||||
Sequence.new.to_fun.
|
||||
select( &:even?).
|
||||
collect {|i| i/3 }.
|
||||
select( &:even?).
|
||||
collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }.
|
||||
flatten. # It flattens everything! Not like: collect {|i| i.flatten }.
|
||||
p
|
||||
|
||||
If you know methodphitamine, combine it:
|
||||
|
||||
require 'methodphitamine'
|
||||
|
||||
Sequence.new.to_fun.
|
||||
select( &it.even?).
|
||||
collect( &it/3).
|
||||
select( &it.even?).
|
||||
collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }.
|
||||
flatten.
|
||||
p
|
||||
|
||||
(0..100000).to_fun.
|
||||
collect( &it*3).
|
||||
select( &it%5 == 2).
|
||||
to_a
|
||||
|
||||
Makros
|
||||
======
|
||||
|
||||
seq = Sequence.new.to_fun
|
||||
seq = seq.select &it.even? if must_be_even
|
||||
seq = seq.
|
||||
collect( &it/3).
|
||||
select( &it.even?).
|
||||
collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }
|
||||
seq = seq.flatten if please_flatten
|
||||
if print_it
|
||||
seq.p
|
||||
else
|
||||
seq_to_a
|
||||
end
|
||||
|
||||
What's with _#map_?
|
||||
=================
|
||||
|
||||
|
|
Reference in a new issue