Improve decode.one_of
API
#4181
ghivert
started this conversation in
Ideas & suggestions
Replies: 2 comments 13 replies
-
I don't find the justification of it being "weird" very compelling as that term doesn't have any useful meaning. The |
Beta Was this translation helpful? Give feedback.
11 replies
-
How would we do the example from the
Using elm's parser-combinators as prior art, I would think edit: to be clear I'm suggesting a rename, just pointing out that |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently rewriting my old decoders with the new
gleam/dynamic/decode
API, and I think it's time now to talk about areas of improvements, before the stdlib bumps to v1.0.0.decode.one_of
I find
decode.one_of
a bit weird, because of the nature of decoders. In previous decoding libraries, we could simply writeone_of
asdecode.one_of([decoders])
. Now, we're forced to write it asdecode.one_of(first_decoder, or: [decoders])
. I feel that it can be difficult to understand why we have to put a decoder in the first place, and not in a list like the others. I think we could add adecode.or
function instead of thedecode.one_of
, because it would make more sense, it can be piped easily, and can be used in an easy in different place. When you have aDecoder(a)
, and you suddenly need to parse a different shape, you don't have to rewrite your existing decoder, but instead pipe it indecode.or
.An example:
I'm not sure it's really the best API or not, but I would find a bit more intuitive, and it avoid to explain why we need to pass a decoder as first argument.
Beta Was this translation helpful? Give feedback.
All reactions