Wraps a value so that "present of absent" is distinguishable from absent.
Maybe[+A] is an opaque type alias for A | Absent.type | Present[A]. A plain non-absent value of type A is a present Maybe[A] with zero allocation; the Absent singleton is Maybe.absent; and Present(a) is a present Maybe[A] whose value is a — used to represent "present of absent" in nested Maybes (e.g. Maybe.present(Maybe.absent)), which a bare Absent cannot express.
NOTE on soundness: Maybe.present (and only present) wraps a user-supplied Present[_] argument in an extra Present layer (present(Present(x)) == Present(Present(x))). This ensures unsafeGet (used by codecs) returns the correct inner Present(x) without double-unwrapping. The public case Present(v) / case Absent matching idiom is unaffected.
Attributes
- Companion
- object
- Source
- Maybe.scala
- Graph
-
- Supertypes