kalekundert / byoc

MIT License
0 stars 0 forks source link

Make it easier to compose cast functions. #13

Closed kalekundert closed 3 years ago

kalekundert commented 3 years ago

Cast functions can be trivially composed, because each takes exactly one argument and returns exactly one value. This can currently be done using a lambda function, but the syntax is verbose:

appcli.param(
    ...
    cast=lambda x: f(g(x)),
    ...
)

I think it could be convenient to interpret a list of cast functions as functions to be composed. In other words, the snippet below would be equivalent to the snippet above:

appcli.param(
    ...
    cast=[g, f],
    ...
)
kalekundert commented 3 years ago

Another advantage of supporting this implicit function composition syntax is that I can give better error messages: if one of the functions fails, I can say exactly which one.