Currently jreqWith etc require that the codec passed to them is a "pair of functions" type codec. Such as (JsonValue -> a' ParseResult) * (a' -> JsonValue). However, when defining codecs for more complex types it's preferable to use the applicative style which creates a ConcreteCodec. It's then cumbersome to use this codec in another codec as it requires converting back to "pair of functions" type by doing codec |> Codec.ofConcrete |> Codec.compose jsonObjToValueCodec.
As an example consider the following types:
type Foo = { X: int }
type Bar = { Foo: Foo }
Then you might want to define codecs for them in another module which currently requires writing them like this:
module Foo =
let codec =
fun x -> { X = x }
<!> jreq "x" (fun x -> x.X)
module Bar =
let codec =
fun foo -> { Foo = foo }
<!> jreqWith (Foo.codec |> Codec.ofConcrete |> Codec.compose jsonObjToValueCodec) "foo" (fun x -> x.Foo)
So it would be nicer if we could avoid having to convert between the two codec representations.
Currently
jreqWithetc require that the codec passed to them is a "pair of functions" type codec. Such as(JsonValue -> a' ParseResult) * (a' -> JsonValue). However, when defining codecs for more complex types it's preferable to use the applicative style which creates aConcreteCodec. It's then cumbersome to use this codec in another codec as it requires converting back to "pair of functions" type by doingcodec |> Codec.ofConcrete |> Codec.compose jsonObjToValueCodec.As an example consider the following types:
Then you might want to define codecs for them in another module which currently requires writing them like this:
So it would be nicer if we could avoid having to convert between the two codec representations.