decipher
decipher copied to clipboard
update to new decode api
Are there any plans to upgrade to the new decode API? I could try to tackle this :)
functions like this
pub fn non_negative_int(dynamic: Dynamic) -> Result(Int, List(DecodeError)) {
use int <- result.try(dynamic.int(dynamic))
case int >= 0 {
True -> Ok(int)
False ->
Error([
DecodeError(
expected: "A non-negative int",
found: int.to_string(int),
path: [],
),
])
}
}
would become split into two:
pub fn non_negative_int(dynamic: Dynamic) -> Result(Int, List(DecodeError)) {
decode.run(dynamic, non_negative_int_decoder())
}
pub fn non_negative_int_decoder() -> Decoder(Int) {
use int <- decode.then(decode.int)
case int >= 0 {
True -> decode.success(int)
False -> decode.failure(0, "A non-negative int")
}
}
This is a breaking change in the sense that the DecodeError type changes (dynamic.DecodeError vs decode.DynamicError).
Or would you rather just keep the function but change the signature (i.e., return a Decoder(a)). This would of course be a larger breaking change but I'm fine with that as well :)