kantan.codecs

Result

sealed abstract class Result[+F, +S] extends Product with Serializable

Represents the result of a decode operation

This is very similar to Either, with a few more bells and whistles and a more specific type. It's also much more convenient to use in for-comprehensions, as it has proper map and flatMap methods.

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Result
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Result()

Abstract Value Members

  1. abstract def canEqual(that: Any): Boolean

    Definition Classes
    Equals
  2. abstract def ensure[FF >: F](fail: ⇒ FF)(f: (S) ⇒ Boolean): Result[FF, S]

    Turns any success whose underlying value doesn't validate the specified predicate into a failure.

    Turns any success whose underlying value doesn't validate the specified predicate into a failure.

    This is useful when not all successes are interesting. One might receive, for example, a success containing an int, but need to further reduce its domain to positive ints and turn any other into a failure.

  3. abstract def exists(f: (S) ⇒ Boolean): Boolean

    Returns the result of applying the specified predicate to the underlying value if a success, false otherwise.

  4. abstract def flatMap[FF >: F, SS](f: (S) ⇒ Result[FF, SS]): Result[FF, SS]

  5. abstract def fold[A](ff: (F) ⇒ A, fs: (S) ⇒ A): A

  6. abstract def forall(f: (S) ⇒ Boolean): Boolean

    Returns the result of applying the specified predicate to the underlying value if a success, false otherwise.

  7. abstract def foreach(f: (S) ⇒ Unit): Unit

    Applies the specified procedure on the underlying value if a success, does nothing otherwise.

    Applies the specified procedure on the underlying value if a success, does nothing otherwise.

    This is useful when one wants to have side-effects that depend on the success' value - print it, for example.

  8. abstract def get: S

    Returns the underlying value if a success, throws an exception otherwise.

    Returns the underlying value if a success, throws an exception otherwise.

    Other value retrieval methods, such as getOrElse or valueOr, should almost always be preferred.

  9. abstract def getOrElse[SS >: S](default: ⇒ SS): SS

    Returns the underlying value if a success, the specified default value otherwise.

    Returns the underlying value if a success, the specified default value otherwise.

    This is useful when one needs to provide a default value in case of a failure.

  10. abstract def isSuccess: Boolean

    Returns true if the result is a success.

  11. abstract def leftFlatMap[FF, SS >: S](f: (F) ⇒ Result[FF, SS]): Result[FF, SS]

  12. abstract def leftMap[FF](f: (F) ⇒ FF): Result[FF, S]

  13. abstract def map[SS](f: (S) ⇒ SS): Result[F, SS]

  14. abstract def orElse[FF >: F, SS >: S](default: ⇒ Result[FF, SS]): Result[FF, SS]

    Returns the specified default value if a failure, does nothing otherwise.

  15. abstract def productArity: Int

    Definition Classes
    Product
  16. abstract def productElement(n: Int): Any

    Definition Classes
    Product
  17. abstract def recover[SS >: S](pf: PartialFunction[F, SS]): Result[F, SS]

    Turns any failure whose value is defined for specified partial function into a success with the corresponding value.

    Turns any failure whose value is defined for specified partial function into a success with the corresponding value.

    This is useful when some error conditions are actually valid answers - one could imagine, for instance, that failure to parse a boolean could be turned into a successful parsing of false.

  18. abstract def recoverWith[SS >: S, FF >: F](pf: PartialFunction[F, Result[FF, SS]]): Result[FF, SS]

    Turns any failure whose value is defined for specified partial function into the corresponding value.

    Turns any failure whose value is defined for specified partial function into the corresponding value.

    This is useful when some error conditions have fallback solutions - one could imagine, for instance, that failure to parse a file because it does not exist can be retried on a secondary possible location for the file.

  19. abstract def toEither: Either[F, S]

    Turns a success into a Right and a failure into a Left.

  20. abstract def toList: List[S]

    Turns a success into a singleton list and a failure into an empty list.

  21. abstract def toOption: Option[S]

    Turns a success into a Some and a failure into a None.

  22. abstract def valueOr[SS >: S](f: (F) ⇒ SS): SS

    Returns the underlying value if a success, the result of applying the specified function to the failure value otherwise.

    Returns the underlying value if a success, the result of applying the specified function to the failure value otherwise.

    This is typically useful when one needs to provide a default value that depends on how an operation failed.

    See also

    recover, recoverWith

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def biFlatMap[FF >: F, SS >: S](f: (FF) ⇒ Result[FF, SS], s: (SS) ⇒ Result[FF, SS]): Result[FF, SS]

  8. def bimap[FF, SS](f: (F) ⇒ FF, s: (S) ⇒ SS): Result[FF, SS]

  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def foldLeft[A](acc: A)(f: (A, S) ⇒ A): A

  14. def foldRight[A](acc: A)(f: (S, A) ⇒ A): A

  15. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  17. def isFailure: Boolean

    Returns true if the result is a failure.

  18. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  20. final def notify(): Unit

    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  22. def productIterator: Iterator[Any]

    Definition Classes
    Product
  23. def productPrefix: String

    Definition Classes
    Product
  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  25. def toString(): String

    Definition Classes
    AnyRef → Any
  26. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped