Skip to content

Instantly share code, notes, and snippets.

@leikind
Created November 7, 2016 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/8ef12333a6b801168138cb7a3b2a8612 to your computer and use it in GitHub Desktop.
Save leikind/8ef12333a6b801168138cb7a3b2a8612 to your computer and use it in GitHub Desktop.
# 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