Skip to content

Conversation

@rap1ds
Copy link
Owner

@rap1ds rap1ds commented Aug 23, 2014

or_else

or_else returns the current Maybe if it's a Some, but if it's a None, it returns the parameter that was given to it (which should be a Maybe).

Here's an example: Show "title", which is person's job title or degree if she doesn't have a job or "Unknown" if both are missing.

maybe_person = Maybe(person)

title = maybe_person.job.title.or_else { maybe_person.degree }.get_or_else { "Unknown" }

title = if person && person.job && person.job.title.present?
  person.job.title
elsif person && person.degree.present?
  person.degree
else
  "Unknown"
end

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.

1 participant