How do I access elements of Pair? Eg as used in the example of map2, zipped = List.map2 ["a", "b", "c"] [1, 2, 3] Pair
. If I pipe this to List.all
how do I unpack/destructure the elements of the pair? I tried \p -> p.0 == p.1
which seems to be tuple unpacking, and \p -> p.first == p.second
, which tries to bind to a record with members first/second. (my example has integers in both lists, not string and int like the map2 example, so equality testing should be ok)
So you used a tag as your map2 joining function
So you have created Pair Str (Num a)
So you would destructive the pair something like \Pair str int -> ...
Also, you can destructive with a record or tuple as well:
\{first, second} -> ...
\(first, second) -> ...
With the record, the names would need to match the field name
For tags and tuples, the name can be anything
And of course, instead of using Pair
, you could just build a tuple or record:
List.map2 ["a", ...] [1, ...] \a, b -> (a, b)
If you use a tuple, you can access the fields with .0, .1, .2, etc:
("hello", "world").1 == "world"
List.map [("hello", "world")] .1 == ["world"]
Last updated: Jul 06 2025 at 12:14 UTC