io.github.netvl.picopickle.TypesComponent
Checks if this reader can handle the provided value.
Checks if this reader can handle the provided value.
a backend value
true
if this reader can read from value
, false
otherwise
Deserializes the value of the specified type from the provided backend value.
Deserializes the value of the specified type from the provided backend value.
This method should fail with an exception if canRead returns false
on this value and it returns a deserialized object successfully otherwise.
a backend value
deserialized variant of value
Returns a reader which applies the given function to the result of the deserialization.
Returns a reader which applies the given function to the result of the deserialization.
result type
a transformation function
a reader which reads a value of type T
and then applies f
to obtain a value of type U
A shorthand for this.orElse(Reader(other))
, where other
is a partial function.
A shorthand for this.orElse(Reader(other))
, where other
is a partial function.
See Reader.apply.
a partial function which is used to create the fallback reader
see another orElse
method
Combines this reader with the specified fallback reader which is used if this reader can't handle the provided value based on its canRead result.
Combines this reader with the specified fallback reader which is used if this reader can't handle the provided value based on its canRead result.
the fallback reader
a reader which delegates to this reader if this reader can deserialize a value
or to the other
reader otherwise
Deserializes the value of the specified type from the provided backend value or applies the given function if it is impossible.
Deserializes the value of the specified type from the provided backend value or applies the given function if it is impossible.
This method is equivalent to if (this.canRead(value)) this.read(value) else fallback(value)
(which is in fact its default implementation) but it can be overridden to avoid excessive
checks. See PartialFunction.applyOrElse method for longer explanation.
Reader.apply and Reader.reading method overrides this method to employ the provided partial function
applyOrElse
method. Consider implementing this method for your readers if for some
reason you don't use Reader.apply
or Reader.reading
.
a backend value
a fallback function
deserialized variant of value
or the result of fallback
application
A type class for reading a backend representation into an object of the specified type.
All deserialization is done by implicit instances of this trait.
Most clients don't need to subclass this trait directly; use Reader companion object to create readers.
Deserialization process can fail if its input is not valid. Consequently, readers are more like partial functions: they can fail on certain inputs.
target type