Conversation
|
ACK. Cool man, thanks! I am going to need a bit to dig into this; a bit slammed right now. A few initial thoughts/questions:
Again, just want to clarify the purpose here. I like the concept a lot just want to make sure we are adding the right thing in the right place. |
|
Haha - I'm not sure if it's "the right thing in the right place" as much as me just screwing around. Yeah - just like threading in Clojure - except that each intermediate value is an Option as well, meaning that any method in the threading could potentially return a nil, producing a NoneClass, so that the rest of the operations won't fail. I've thought about doing something like this before...but maybe make it less haskelly and amenable to enumerables, like: # anarray could be empty, but if it has at least one element,
# then the block will be called with it
Option(anarray).if_first { |one| ... }
# or, alternately something like
Option(anarray).if_not(:empty?) { |a| ... }
# and then allow for threading per element
Option([" 1 ", " 2 ", " 3 "]).thread(:strip, :to_i, :next)
# => [2,3,4]
# which is way prettier and efficient than
[" 1 ", " 2 ", " 3 "].map(&:strip).map(&:to_i).map(&:next)
# and at least way prettier than
[" 1 ", " 2 ", " 3 "].map { |i| i.strip.to_i.next }
# PLUS if any of the intermediate method calls returns nil, then you still get a result, like
Option([" 1 ", " 2 ", " 3 "]).thread(:strip, :make_a_nil, :to_i, :next)
#=> [<NoneClass instance>, <NoneClass instance> <NoneClass instance>] |
|
Ok, I see where you are going with the def lift_option
map { |v| Option(v) }
endor def first_option
Option(first)
end
def last_option
Option(last)
endAs for the proposed feature itself, I want to add it but first a few questions/requests:
Anyways, thanks for the work and let me know what you think about item number 2. |
Just for funzies...