pzol / deterministic

Functional - deterministic - Ruby made fun
MIT License
187 stars 18 forks source link

Pattern matching on Maybe #27

Open ianks opened 9 years ago

ianks commented 9 years ago

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?

pzol commented 9 years ago

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

Piotr

On 20 Aug 2015, at 00:55, Ian Ker-Seymer notifications@github.com 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.