What about something like this?
decodeTouches : Decoder (List Touch)
decodeTouches =
Decode.field "length" Decode.int
|> Decode.andThen
(\len ->
case len of
1 ->
Decode.map (\a -> [ a ])
(Decode.field "1" touchDecoder)
2 ->
Decode.map2 (\a b -> [ a, b ])
(Decode.field "1" touchDecoder)
(Decode.field "2" touchDecoder)
3 ->
Decode.map3 (\a b c -> [ a, b, c ])
(Decode.field "1" touchDecoder)
(Decode.field "2" touchDecoder)
(Decode.field "3" touchDecoder)
_ ->
Decode.fail "Unexpected length"
)
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.