Skip to content

Conversation

@camertron
Copy link

This PR adds scala-style matching to options so you can do stuff like this:

result = Option(variable).match do |matcher|
  matcher.case(Some[Fixnum]) { |val| val * 2 }
  matcher.case(Some[String]) { |val| val.length }
end

result  # => 10 when variable is 5, 6, when variable is "option"

You can also match without types:

Option(variable).match do |matcher|
  matcher.case(Some) { |val| puts val }
  matcher.case(None) { |val| raise StandardError }
end

Finally, the OptionMatcher also supports else:

Option(variable).match do |matcher|
  matcher.case(Some[String]) { ... }
  matcher.else { |val| ... }
end

@rares
Copy link
Owner

rares commented Mar 11, 2014

ack

I'm a little swamped right now so I will probably take me a few weeks to review.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants