Method: Collins::Option#flat_map
- Defined in:
- lib/collins/option.rb
#flat_map(&block) ⇒ Option<Object>
Same as map, but flatten the results
This is useful when operating on an object that will return an ‘Option`.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/collins/option.rb', line 128 def flat_map &block if empty? then None.new else res = block.call(get) if res.is_a?(Some) then res else Some.new(res) end end end |