Prism

dev.constructive.eo.optics.Prism
object Prism

Constructors for Prism — the partial single-focus optic, backed by Either. A Prism[S, A] (short for Optic[S, S, A, A, Either]) encodes a branch of a sum type: getOption(s) succeeds when s matches, reverseGet(a) lifts back. The eo-generics module's prism[S, A] macro derives prisms on enums / sealed traits / union types.

Attributes

Source
Prism.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Prism.type

Members list

Grouped members

Constructors

def apply[S, A](getOrModify: S => Either[S, A], reverseGet: A => S): MendTearPrism[S, S, A, A]

Monomorphic constructor (S = T, A = B). getOrModify returns Right(a) on match and Left(s) on miss.

Monomorphic constructor (S = T, A = B). getOrModify returns Right(a) on match and Left(s) on miss.

Attributes

Example
enum Shape:
 case Circle(r: Double)
 case Square(s: Double)
val circleP = Prism[Shape, Shape.Circle](
 { case c: Shape.Circle => Right(c); case other => Left(other) },
 identity,
)
Source
Prism.scala
def optional[S, A](getOption: S => Option[A], reverseGet: A => S): PickMendPrism[S, A, A]

Option-shaped constructor — returns a PickMendPrism whose fused extensions avoid the intermediate Either the generic constructor must build. Prefer when the projection is already S => Option[A].

Option-shaped constructor — returns a PickMendPrism whose fused extensions avoid the intermediate Either the generic constructor must build. Prefer when the projection is already S => Option[A].

Attributes

Source
Prism.scala
def pOptional[S, A, B](getOption: S => Option[A], reverseGet: B => S): PickMendPrism[S, A, B]

Polymorphic counterpart to optional — type change on write.

Polymorphic counterpart to optional — type change on write.

Attributes

Source
Prism.scala
def pPrism[S, T, A, B](getOrModify: S => Either[T, A], reverseGet: B => T): MendTearPrism[S, T, A, B]

Polymorphic constructor — allows the miss branch to produce a different T. For refinement-style conversions; most code wants apply.

Polymorphic constructor — allows the miss branch to produce a different T. For refinement-style conversions; most code wants apply.

Attributes

Source
Prism.scala