Constructor for Optional — the conditionally-present single-focus optic, backed by Affine. "An Optional[S, A]" is prose shorthand for Optic[S, S, A, A, Affine] — there is NO two-parameter alias to ascribe; the concrete Optional class below always takes all four parameters (Optional[S, S, A, A] for the monomorphic case). Ascribing the concrete class is fine — that keeps code on the hot, fused paths; what would knock it off is ascribing the generic Optic[…], which drops the fused compose overloads and capability mixins for generic dispatch. Optional.apply returns that concrete class, so leave vals un-ascribed (or name the four-parameter class) and let consuming signatures demand a capability (CanGetOption[S, A], CanModify[S, A], …) instead. An optional encodes a field that may or may not be there. Composes freely with Lens via cross-carrier .andThen (auto-morphs through Composer[Tuple2, Affine]).
'''Miss semantics (normative).''' A write through a missed optional is a silent identity pass-through: modify(f)(s) and replace(b)(s) return s unchanged (f is never invoked), and foldMap folds zero foci (returns Monoid.empty). No error, no signal. When hit-ness matters, probe with .getOption first.
Attributes
- Companion
- class
- Source
- Optional.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Optional.type