deterministic icon indicating copy to clipboard operation
deterministic copied to clipboard

Pattern matching on Maybe

Open ianks opened this issue 10 years ago • 1 comments

I would like to be able to do somehting like this

Maybe(nil).match do
  Some(s) { |v| s }
  None(n) { |v| SomeObject.new }
end #=> SomeObject.new

Is this possible/is there a better pattern than this for having this behavior?

ianks avatar Aug 19 '15 21:08 ianks

did you try Maybe(nil).value_or SomeObject.new ?

Piotr

On 20 Aug 2015, at 00:55, Ian Ker-Seymer [email protected] wrote:

I would like to be able to do somehting like this

Maybe(nil).match do Some(s) { |v| s } None(n) { |v| SomeObject.new } end Is this possible/is there a better pattern than this for having this behavior?

— Reply to this email directly or view it on GitHub.

pzol avatar Aug 20 '15 10:08 pzol