Skip to content

Commit

Permalink
Add present method on Maybe as the antithesis of unset
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Dec 1, 2023
1 parent ef367e3 commit d1b17d5
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/core/maybe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ case class UnsetValueError() extends Error(Message("the value was not set".tt))

extension [ValueType](maybe: Maybe[ValueType])
inline def unset: Boolean = maybe == Unset
inline def present: Boolean = maybe != Unset
inline def or(inline value: => ValueType): ValueType = if unset then value else maybe.asInstanceOf[ValueType]
inline def vouch(using Unsafe): ValueType = or(throw Mistake(msg"a value was vouched but was unset"))

Expand Down

0 comments on commit d1b17d5

Please sign in to comment.