Package

kantan

codecs

Permalink

package codecs

Visibility
  1. Public
  2. All

Type Members

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

    Permalink

    Combines a Decoder and an Encoder.

    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.

  2. trait CodecCompanion[E, F, T] extends AnyRef

    Permalink
  3. trait Decoder[E, D, F, T] extends Serializable

    Permalink

    Type class for types that can be decoded from other types.

    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.

  4. trait DecoderCompanion[E, F, T] extends AnyRef

    Permalink

    Provides methods commonly declared by companion objects for specialised decoder types.

    Provides methods commonly declared by companion objects for specialised decoder types.

    Most libraries that use kantan.codecs will declare type aliases for decoders - CellDecoder in kantan.csv, for example. DecoderCompanion lets such types have a useful companion object without a lot of code duplication.

  5. trait Encoder[E, D, T] extends Serializable

    Permalink

    Type class for types that can be encoded into others.

    Type class for types that can be encoded into others.

    E

    encoded type - what to encode to.

    D

    decoded type - what to encode from.

    T

    tag type.

  6. trait EncoderCompanion[E, T] extends AnyRef

    Permalink
  7. abstract class Error extends Exception with Product with Serializable

    Permalink

    Base class for errors

    Base class for errors

    This is specifically meant for errors represented as ADTs. The fact that it extends Exception is an unfortunate side effect of the Scala stdlib's reliance on exceptions, as seen with scala.concurrent.Future and scala.util.Try, for example.

  8. abstract class ErrorCompanion[T <: Error] extends AnyRef

    Permalink

    Provides useful instance creation methods for errors that might be created as a result of Java exceptions.

  9. trait Optional[A] extends AnyRef

    Permalink

    Type class that represents data types that have an "empty" value.

    Type class that represents data types that have an "empty" value.

    The purpose of this type class is to allow automatic derivation of Decoder for decoded types that might not have a value - Option, List...

    In theory, there should rarely be a need to interact directly with this type class, and one is usually better served by obtaining the Decoder instance for Option and mapping on it.

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

    Permalink

    Represents the result of a decode operation

    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.

Value Members

  1. object Codec extends Serializable

    Permalink
  2. object Decoder extends Serializable

    Permalink
  3. object Encoder extends Serializable

    Permalink
  4. object Optional

    Permalink
  5. object Result extends Serializable

    Permalink
  6. object ResultCompanion

    Permalink

    Provides trait that result companion object can extend.

    Provides trait that result companion object can extend.

    The idea is that libraries that rely on kantan.codecs are likely to provide type-constrained versions of result, such as DecodeResult in kantan.csv. Users are likely to expect goodies such as fromTry or sequence on DecodeResult's companion object, which can be achieved by extending kantan.codecs.ResultCompanion.WithDefault.

  7. package export

    Permalink

    Provides a simple mechanism to insert derived type class instances in the implicit resolution mechanism.

    Provides a simple mechanism to insert derived type class instances in the implicit resolution mechanism.

    By default, when imported, such instances have the highest possible priority, which is typically problematic with shapeless instance derivation: bespoke instances for Option or Either, for example, find themselves shadowed by the generically derived ones.

    If such instances are of type kantan.codecs.export.DerivedDecoder / kantan.codecs.export.DerivedEncoder rather than Decoder / Encoder, however, they'll find themselves with a lower precedence and only be used if no other, more specific instance is found.

  8. package resource

    Permalink
  9. package strings

    Permalink

    Defines codecs for encoding to and decoding from strings.

    Defines codecs for encoding to and decoding from strings.

    These codecs are not necessary meant to use directly, but more as part of larger ones. kantan.csv, for example, works with CSV files but delegates the act of encoding to or decoding from a CSV cell to string codecs.

    Default instances can be found in kantan.codecs.strings.codecs.

Ungrouped