Summons an implicit instance of StringDecoder[D]
if one can be found, fails compilation otherwise.
Summons an implicit instance of StringDecoder[D]
if one can be found, fails compilation otherwise.
This is equivalent to calling implicitly[StringDecoder[D]]
, with the following advantages:
Creates a StringDecoder instance for java.util.Date
.
Creates a StringDecoder instance for java.util.Date
.
scala> import java.text.SimpleDateFormat scala> val format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz") scala> implicit val decoder: StringDecoder[java.util.Date] = StringDecoder.dateDecoder(format) scala> decoder.decode("2016-01-17T22:03:12.012UTC").map(format.format) res1: kantan.codecs.Result[DecodeError, String] = Success(2016-01-17T22:03:12.012UTC)
format used when parsing date values.
Creates an instance of StringDecoder from the specified decoding function.
Creates an instance of StringDecoder from the specified decoding function.
decoded type
how to decode to D
.
Creates a safe decoding function from the specified unsafe one.
Creates a safe decoding function from the specified unsafe one.
This method expects the specified decoding function to be able to fail by throwing exceptions. These will be caught and wrapped in DecodeError.
scala> val decoder = StringDecoder.makeSafe("Int")(_.toInt) scala> decoder("1") res1: kantan.codecs.Result[DecodeError, Int] = Success(1) scala> decoder("foobar") res2: kantan.codecs.Result[DecodeError, Int] = Failure(DecodeError: 'foobar' is not a valid Int)
This is typically used in conjunction with [StringDecoder.from], when creating instances for types that are not
isomorphic to String
.
decoded type.
name of the decoded type (used in error messages).
decoding function.
Provides instance creation and summing methods for StringDecoder.
Default StringDecoder instances are provided in codecs.