o

monocle

Optional

object Optional

Source
Optional.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Optional
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[S, A](_getOption: (S) => Option[A])(_set: (A) => (S) => S): Optional[S, A]

    alias for POptional apply restricted to monomorphic update

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. 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
    See also

    This method is called filtered in Haskell Lens.

  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. def void[S, A]: Optional[S, A]

    Optional that points to nothing

  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def codiagonal[S]: Optional[Either[S, S], S]
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M4) use Lens.codiagonal

  2. def id[A]: Optional[A, A]
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0-M2) use Iso.id

Inherited from AnyRef

Inherited from Any

Ungrouped