Closed mlms13 closed 4 years ago
Just a quick note, you can already do this pretty easily with pure()
, which creates a decoder that will always succeed with ()
. I'm less convinced now that this case is so important that we need to provide a special function to do this.
Alternatively, there was a suggestion in Discord awhile ago to add a "decoder" that always succeeds with the JSON input it was given. This can already be achieved (e.g. with Result.pure
or Option.pure
), but it locks you in to that specific monad, meaning you'd have to find and replace that code if you wanted to switch from one to the other.
So I'm inclined to add a helper for this, but naming becomes difficult because json
is likely to cause issues with shadowing, and id
has a slightly different meaning (and might also shadow things). Maybe okJson
or just ok
?
Opted for okJson
. This will be included in the next release.
In some cases, it may be useful to have a decoder that takes in JSON and always returns a successful
()
. For example:tuple
decoders, if you have a JSON array like:["A", 0, someReallyComplexObject, false]
, even if you don't care about the complex object, you have to write a decoder for it if you want to pick out the other 3 itemsDecode.(array(unit) |> map (Array.length))
without needing to write a real decoder for the inner structure