Optional

monocle.Optional$
object Optional

Attributes

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

Members list

Concise view

Value members

Concrete methods

def apply[S, A](_getOption: S => Option[A])(_set: A => S => S): Optional[S, A]

alias for POptional apply restricted to monomorphic update

alias for POptional apply restricted to monomorphic update

Attributes

Source:
Optional.scala
def filter[A](predicate: A => Boolean): Optional[A, A]

Select all the elements which satisfies the predicate.

Select all the elements which satisfies the predicate.

 val positiveNumbers = Traversal.fromTraverse[List, Int] composeOptional filter[Int](_ >= 0)

 positiveNumbers.getAll(List(1,2,-3,4,-5)) == List(1,2,4)
 positiveNumbers.modify(_ * 10)(List(1,2,-3,4,-5)) == List(10,20,-3,40,-5)

filter can break the fusion property, if replace or modify do not preserve the predicate. For example, here the first modify (x - 3) transform the positive number 1 into the negative number -2.

 val positiveNumbers = Traversal.fromTraverse[List, Int] composeOptional Optional.filter[Int](_ >= 0)
 val list            = List(1, 5, -3)
 val firstStep       = positiveNumbers.modify(_ - 3)(list)            // List(-2, 2, -3)
 val secondStep      = positiveNumbers.modify(_ * 2)(firstStep)       // List(-2, 4, -3)
 val bothSteps       = positiveNumbers.modify(x => (x - 3) * 2)(list) // List(-4, 4, -3)
 secondStep != bothSteps

Attributes

See also:

This method is called filtered in Haskell Lens.

Source:
Optional.scala
def void[S, A]: Optional[S, A]

Optional that points to nothing

Optional that points to nothing

Attributes

Source:
Optional.scala

Deprecated methods

def codiagonal[S]: Optional[Either[S, S], S]

Attributes

Deprecated
[Since version 3.0.0-M4]
Source:
Optional.scala
def id[A]: Optional[A, A]

Attributes

Deprecated
[Since version 3.0.0-M2]
Source:
Optional.scala