trait POptional[S, T, A, B] extends PTraversal[S, T, A, B]

A POptional can be seen as a pair of functions:

  • getOrModify: S => Either[T, A]
  • replace : (B, S) => T

A POptional could also be defined as a weaker PLens and weaker PPrism

POptional stands for Polymorphic Optional as it replace and modify methods change a type A to B and S to T. Optional is a type alias for POptional restricted to monomorphic updates:

type Optional[S, A] = POptional[S, S, A, A]
S

the source of a POptional

T

the modified source of a POptional

A

the target of a POptional

B

the modified target of a POptional

Self Type
POptional[S, T, A, B]
Source
Optional.scala
See also

monocle.law.OptionalLaws

Linear Supertypes
PTraversal[S, T, A, B], Fold[S, A], PSetter[S, T, A, B], Serializable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. POptional
  2. PTraversal
  3. Fold
  4. PSetter
  5. Serializable
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def getOption(s: S): Option[A]

    get the target of a POptional or nothing if there is no target

  2. abstract def getOrModify(s: S): Either[T, A]

    get the target of a POptional or return the original value while allowing the type to change if it does not match

  3. abstract def modifyA[F[_]](f: (A) => F[B])(s: S)(implicit arg0: Applicative[F]): F[T]

    modify polymorphically the target of a PTraversal with an Applicative function all traversal methods are written in terms of modifyA

    modify polymorphically the target of a PTraversal with an Applicative function all traversal methods are written in terms of modifyA

    Definition Classes
    PTraversal

Concrete Value Members

  1. def all(p: (A) => Boolean): (S) => Boolean

    check if there is no target or the target satisfies the predicate

    check if there is no target or the target satisfies the predicate

    Definition Classes
    POptionalFold
  2. def andThen[C, D](other: POptional[A, B, C, D]): POptional[S, T, C, D]

    compose a POptional with a POptional

  3. def andThen[C, D](other: PTraversal[A, B, C, D]): PTraversal[S, T, C, D]

    compose a PTraversal with another PTraversal

    compose a PTraversal with another PTraversal

    Definition Classes
    PTraversal
  4. def andThen[B](other: Fold[A, B]): Fold[S, B]

    compose a Fold with another Fold

    compose a Fold with another Fold

    Definition Classes
    Fold
  5. def andThen[C, D](other: PSetter[A, B, C, D]): PSetter[S, T, C, D]

    compose a PSetter with another PSetter

    compose a PSetter with another PSetter

    Definition Classes
    PSetter
  6. def asFold: Fold[S, A]

    view a PTraversal as a Fold

    view a PTraversal as a Fold

    Definition Classes
    PTraversal
  7. def asSetter: PSetter[S, T, A, B]

    view a PTraversal as a PSetter

    view a PTraversal as a PSetter

    Definition Classes
    PTraversal
  8. def asTraversal: PTraversal[S, T, A, B]

    view a POptional as a PTraversal

  9. def exist(p: (A) => Boolean): (S) => Boolean

    check if there is a target and it satisfies the predicate

    check if there is a target and it satisfies the predicate

    Definition Classes
    POptionalFold
  10. def find(p: (A) => Boolean): (S) => Option[A]

    find if the target satisfies the predicate

    find if the target satisfies the predicate

    Definition Classes
    POptionalFold
  11. def fold(s: S)(implicit ev: Monoid[A]): A

    combine all targets using a target's Monoid

    combine all targets using a target's Monoid

    Definition Classes
    Fold
  12. def foldMap[M](f: (A) => M)(s: S)(implicit arg0: Monoid[M]): M

    map each target to a Monoid and combine the results

    map each target to a Monoid and combine the results

    Definition Classes
    PTraversalFold
  13. def getAll(s: S): List[A]

    get all the targets of a Fold

    get all the targets of a Fold

    Definition Classes
    Fold
  14. def headOption(s: S): Option[A]

    get the first target

    get the first target

    Definition Classes
    Fold
  15. def index[I, A1](i: I)(implicit evIndex: Index[A, I, A1], evMonoS: =:=[S, T], evMonoA: =:=[A, B]): Optional[S, A1]
    Definition Classes
    POptionalPTraversalPSetter
  16. def index[I, A1](i: I)(implicit evIndex: Index[A, I, A1]): Fold[S, A1]
    Definition Classes
    Fold
  17. def isEmpty(s: S): Boolean

    check if there is no target

    check if there is no target

    Definition Classes
    POptionalFold
  18. def lastOption(s: S): Option[A]

    get the last target

    get the last target

    Definition Classes
    Fold
  19. def length(s: S): Int

    calculate the number of targets

    calculate the number of targets

    Definition Classes
    Fold
  20. def modify(f: (A) => B): (S) => T

    modify polymorphically the target of a PTraversal with a function

    modify polymorphically the target of a PTraversal with a function

    Definition Classes
    PTraversalPSetter
  21. def modifyOption(f: (A) => B): (S) => Option[T]

    modify polymorphically the target of a POptional with a function.

    modify polymorphically the target of a POptional with a function. return empty if the POptional is not matching

  22. def nonEmpty(s: S): Boolean

    check if there is a target

    check if there is a target

    Definition Classes
    POptionalFold
  23. def orElse(other: POptional[S, T, A, B]): POptional[S, T, A, B]

    fall-back to another POptional in case this one doesn't match

  24. def parModifyF[F[_]](f: (A) => F[B])(s: S)(implicit F: Parallel[F]): F[T]

    PTraversal.modifyA for a Parallel applicative functor.

    PTraversal.modifyA for a Parallel applicative functor.

    Definition Classes
    PTraversal
  25. def replace(b: B): (S) => T

    replace polymorphically the target of a PTraversal with a value

    replace polymorphically the target of a PTraversal with a value

    Definition Classes
    PTraversalPSetter
  26. def replaceOption(b: B): (S) => Option[T]

    replace polymorphically the target of a POptional with a value.

    replace polymorphically the target of a POptional with a value. return empty if the POptional is not matching

  27. def some[A1, B1](implicit ev1: =:=[A, Option[A1]], ev2: =:=[B, Option[B1]]): POptional[S, T, A1, B1]
    Definition Classes
    POptionalPTraversalPSetter
  28. def some[A1](implicit ev1: =:=[A, Option[A1]]): Fold[S, A1]
    Definition Classes
    Fold
  29. def to[C](f: (A) => C): Fold[S, C]

    Compose with a function lifted into a Getter

    Compose with a function lifted into a Getter

    Definition Classes
    Fold

Deprecated Value Members

  1. def first[C]: POptional[(S, C), (T, C), (A, C), (B, C)]
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M4) no replacement

  2. def left[C]: Fold[Either[S, C], Either[A, C]]
    Definition Classes
    Fold
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M4) no replacement

  3. def right[C]: Fold[Either[C, S], Either[C, A]]
    Definition Classes
    Fold
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M4) no replacement

  4. def second[C]: POptional[(C, S), (C, T), (C, A), (C, B)]
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M4) no replacement

  5. def set(b: B): (S) => T

    alias to replace

    alias to replace

    Definition Classes
    PSetter
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M1) use replace instead

  6. def setOption(b: B): (S) => Option[T]

    alias to replaceOption

    alias to replaceOption

    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M1) use replaceOption instead