Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode a tuple in elm

Tags:

elm

I'm looking for a way to decode a tuple with two elements in elm.

[[String, Bool]]

The outer list is easy enough to parse with Json.list, but how do I decode the array as a tuple ? I tried the solution from Decode a JSON tuple to Elm tuple but all I get is errors about types of Decoder and Maybe, I assume something changed in elm since that answer. Or maybe I'm missing an import, I don't know.

Thanks

like image 349
Ulrar Avatar asked Oct 31 '17 15:10

Ulrar


2 Answers

simplest is

map2 (,) (index 0 string) (index 1 string)
like image 166
Simon H Avatar answered Sep 23 '22 01:09

Simon H


As of elm 0.19 use:

map2 (Tuple.pair) (index 0 string) (index 1 string)

https://github.com/elm/compiler/blob/master/docs/upgrade-instructions/0.19.0.md#changes

like image 36
simplystuart Avatar answered Sep 20 '22 01:09

simplystuart