trait Decoder[E, D, F, T] extends Serializable
Type class for types that can be decoded from other types.
- E
encoded type - what to decode from.
- D
decoded type - what to decode to.
- F
failure type - how to represent errors.
- T
tag type - used to specialise decoder instances, and usually where default implementations are declared.
- Alphabetic
- By Inheritance
- Decoder
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
decode(e: E): Either[F, D]
Decodes encoded data.
Decodes encoded data.
This method is safe, in that it won't throw for run-of-the-mill errors. Unrecoverable errors such as out of memory exceptions are still thrown, but that's considered valid exceptional cases, where incorrectly encoded data is just... normal.
Callers that wish to fail fast and fail hard can use the unsafeDecode method instead.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
andThen[FF, DD](f: (Either[F, D]) ⇒ Either[FF, DD]): Decoder[E, DD, FF, T]
Creates a new Decoder instance by transforming raw results with the specified function.
Creates a new Decoder instance by transforming raw results with the specified function.
Most of the time, other combinators such as map should be preferred. andThen is mostly useful when one needs to turn failures into successes, and even then, recover or recoverWith are probably more directly useful.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
collect[DD](f: PartialFunction[D, DD])(implicit t: IsError[F]): Decoder[E, DD, F, T]
Applies the specified partial function, turning all non-matches to failures.
-
def
contramapEncoded[EE](f: (EE) ⇒ E): Decoder[EE, D, F, T]
Creates a new Decoder instance by transforming encoded values with the specified function.
-
def
emap[DD](f: (D) ⇒ Either[F, DD]): Decoder[E, DD, F, T]
Creates a new Decoder instance by transforming successful results with the specified function.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
filter(f: (D) ⇒ Boolean)(implicit t: IsError[F]): Decoder[E, D, F, T]
Turns all values that don't match the specified predicates into failures.
Turns all values that don't match the specified predicates into failures.
See collect if you wish to transform the values in the same call.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[DD](f: (D) ⇒ Decoder[E, DD, F, T]): Decoder[E, DD, F, T]
- Annotations
- @SuppressWarnings()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def handleErrorWith(f: (F) ⇒ Decoder[E, D, F, T]): Decoder[E, D, F, T]
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
leftMap[FF](f: (F) ⇒ FF): Decoder[E, D, FF, T]
Creates a new Decoder instance by transforming errors with the specified function.
-
def
map[DD](f: (D) ⇒ DD): Decoder[E, DD, F, T]
Creates a new Decoder instance by transforming successful results with the specified function.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
orElse[DD >: D](d: Decoder[E, DD, F, T]): Decoder[E, DD, F, T]
Creates a new Decoder instance with a fallback decoder if the current one fails.
- def product[DD](decoder: Decoder[E, DD, F, T]): Decoder[E, (D, DD), F, T]
-
def
recover[DD >: D](pf: PartialFunction[F, DD]): Decoder[E, DD, F, T]
Creates a new Decoder instance by transforming some failures into successes with the specified function.
-
def
recoverWith[DD >: D, FF >: F](pf: PartialFunction[F, Either[FF, DD]]): Decoder[E, DD, FF, T]
Creates a new Decoder instance by transforming some failures with the specified function.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tag[TT]: Decoder[E, D, F, TT]
Changes the type with which the decoder is tagged.
Changes the type with which the decoder is tagged.
This makes it possible to share similar decoders across various libraries. Extracting values from strings, for example, is a common task for which the default implementation can be shared rather than copy / pasted.
- Annotations
- @SuppressWarnings()
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
unsafeDecode(e: E): D
Decodes encoded data unsafely.
Decodes encoded data unsafely.
The main difference between this and decode is that the former throws exceptions when errors occur where the later safely encodes error conditions in its return type.
decode should almost always be preferred, but this can be useful for code where crashing is an acceptable reaction to failure.
- Annotations
- @SuppressWarnings()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )