kantan.codecs

Codec

trait Codec[E, D, F, T] extends Decoder[E, D, F, T] with Encoder[E, D, T]

Combines a Decoder and an Encoder.

Codecs are only meant as a convenience, and should not be considered more powerful or desirable than encoders or decoders. Some types can be both encoded to and decoded from, and being able to define both instances in one call is convenient. It's however very poor practice to request a type to have a Codec instance - a much preferred alternative would be to require it to have a Decoder and an Encoder instance, which a Codec would fulfill.

Linear Supertypes
Encoder[E, D, T], Decoder[E, D, F, T], Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Codec
  2. Encoder
  3. Decoder
  4. Serializable
  5. Serializable
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def decode(e: E): Result[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.

    Definition Classes
    Decoder
  2. abstract def encode(d: D): E

    Encodes the specified value.

    Encodes the specified value.

    Definition Classes
    Encoder

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. def andThen[FF, DD](f: (Result[F, D]) ⇒ Result[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.

    Definition Classes
    Decoder
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. 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.

    Applies the specified partial function, turning all non-matches to failures.

    You can think as collect as a bit like a filter and a map merged into one.

    Definition Classes
    Decoder
  10. def contramap[DD](f: (DD) ⇒ D): Encoder[E, DD, T]

    Creates a new Encoder instances that applies the specified function before encoding.

    Creates a new Encoder instances that applies the specified function before encoding.

    This is a convenient way of creating Encoder instances: if you already have an Encoder[E, D, R], need to write an Encoder[E, DD, R] and know how to turn a DD into a D, you need but call contramap.

    Definition Classes
    Encoder
  11. def contramapEncoded[EE](f: (EE) ⇒ E): Decoder[EE, D, F, T]

    Creates a new Decoder instance by transforming encoded values with the specified function.

    Creates a new Decoder instance by transforming encoded values with the specified function.

    Definition Classes
    Decoder
  12. def emap[DD](f: (D) ⇒ Result[F, DD]): Decoder[E, DD, F, T]

    Creates a new Decoder instance by transforming successful results with the specified function.

    Creates a new Decoder instance by transforming successful results with the specified function.

    This differs from map in that it allows the transformation function to fail.

    Definition Classes
    Decoder
  13. final def eq(arg0: AnyRef): Boolean

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

    Definition Classes
    AnyRef → Any
  15. 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.

    Definition Classes
    Decoder
  16. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

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

    Definition Classes
    AnyRef → Any
  19. def imap[DD](f: (D) ⇒ DD)(g: (DD) ⇒ D): Codec[E, DD, F, T]

  20. def imapEncoded[EE](f: (E) ⇒ EE)(g: (EE) ⇒ E): Codec[EE, D, F, T]

  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. def leftMap[FF](f: (F) ⇒ FF): Codec[E, D, FF, T]

    Creates a new Decoder instance by transforming errors with the specified function.

    Creates a new Decoder instance by transforming errors with the specified function.

    Definition Classes
    CodecDecoder
  23. def map[DD](f: (D) ⇒ DD): Decoder[E, DD, F, T]

    Creates a new Decoder instance by transforming successful results with the specified function.

    Creates a new Decoder instance by transforming successful results with the specified function.

    This differs from emap in that the transformation function cannot fail.

    Definition Classes
    Decoder
  24. def mapEncoded[EE](f: (E) ⇒ EE): Encoder[EE, D, T]

    Definition Classes
    Encoder
  25. final def ne(arg0: AnyRef): Boolean

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

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

    Definition Classes
    AnyRef
  28. 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.

    Creates a new Decoder instance with a fallback decoder if the current one fails.

    Definition Classes
    Decoder
  29. 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.

    Creates a new Decoder instance by transforming some failures into successes with the specified function.

    Definition Classes
    Decoder
  30. def recoverWith[DD >: D, FF >: F](pf: PartialFunction[F, Result[FF, DD]]): Decoder[E, DD, FF, T]

    Creates a new Decoder instance by transforming some failures with the specified function.

    Creates a new Decoder instance by transforming some failures with the specified function.

    Definition Classes
    Decoder
  31. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  32. def tag[TT]: Codec[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.

    Definition Classes
    CodecEncoderDecoder
    Annotations
    @SuppressWarnings()
  33. def toString(): String

    Definition Classes
    AnyRef → Any
  34. 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.

    Definition Classes
    Decoder
  35. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def mapError[FF](f: (F) ⇒ FF): Codec[E, D, FF, T]

    Definition Classes
    CodecDecoder
    Annotations
    @deprecated
    Deprecated

    (Since version 0.2.1) Use leftMap instead

  2. def mapResult[DD](f: (D) ⇒ Result[F, DD]): Decoder[E, DD, F, T]

    Definition Classes
    Decoder
    Annotations
    @deprecated
    Deprecated

    (Since version 0.2.0) Use emap instead

Inherited from Encoder[E, D, T]

Inherited from Decoder[E, D, F, T]

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped