jaspervdj / digestive-functors

A general way to consume input using applicative functors
149 stars 71 forks source link

Input list using provided defaults #20

Closed chrisdone closed 12 years ago

chrisdone commented 12 years ago

Here is a use case, taken from the example linked from the Cabal file.

Here is the output, I would expect the values in the inputs to be filled in with "foo" "bar" 0.

Am I doing something wrong? I looked at this all evening and the implementation of inputList and I came up with a fix, but I can't tell if it's the correct fix, or whether it breaks some assumptions:

forms = zipWith ($) fs $ maybe (maybe [Nothing] (map Just) defaults)
                               (\i -> take i (maybe [] (map Just) defaults ++ repeat Nothing))
                               countFromForm

From my understanding, this will enable the defaults to be included in all cases, and the repeat Nothing is for non-default inputs added dynamically by the client.

If you can find what I'm doing wrong, or grok this change I propose, I'd appreciate it. I had a hard time grokking this library and this function.

chrisdone commented 12 years ago

There's a patch here, fwiw: https://github.com/chrisdone/digestive-functors/commit/e62afe51e258b9ebd482818dfcc2e04f250b35da

jaspervdj commented 12 years ago

Does this patch fix the issue for you? It doesn't seem to use "0" as a default but that is unrelated to this issue.

chrisdone commented 12 years ago

Seems to be correct. Works!

jaspervdj commented 12 years ago

Up on Hackage as 0.2.0.1, closing this issue.

chrisdone commented 12 years ago

Cheers!