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.
Attributes
- Companion
- object
- Source
- Codec.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Attributes
- Source
- Codec.scala
Attributes
- Source
- Codec.scala
Creates a new Decoder instance by transforming errors with the specified function.
Creates a new Decoder instance by transforming errors with the specified function.
Attributes
- Definition Classes
- Source
- Codec.scala
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.
Attributes
- Definition Classes
- Source
- Codec.scala
Inherited methods
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Encoder
- Source
- Encoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Attributes
- Inherited from:
- Encoder
- Source
- Encoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Inherited and Abstract methods
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.
Attributes
- Inherited from:
- Decoder
- Source
- Decoder.scala
Encodes the specified value.