Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# kinda library code
def pack(v)
[v]
end
class Array
def unpack
self[0]
end
def process(func)
self.map{|v| func.(v) }.compact
end
end
# using it
do_smth_step = ->(v){
v + 1
}
do_smth_and_fail = ->(v){
nil
}
res = pack(123)
.process(do_smth_step)
.process(do_smth_step)
.process(do_smth_step)
.process(do_smth_step)
.process(do_smth_step)
.unpack
p res
res = pack(123)
.process(do_smth_step)
.process(do_smth_step)
.process(do_smth_and_fail)
.process(do_smth_step)
.process(do_smth_step)
.unpack
p res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment