Tuple

Core

Selm has built-in syntax for tuples, so you can define 2D points like this:

origin : (Float, Float)
origin =
    (0, 0)

position : (Float, Float)
position =
    (3, 4)

This module is a bunch of helpers for working with 2-tuples.

**Note:** For more complex data, it is best to switch to records. So instead of representing a 3D point as (3,4,5) and not having any helper functions, represent it as { x = 3, y = 4, z = 5 } and use all the built-in record syntax!

Values

pair

pair : a -> b -> (a, b)

Create a 2-tuple.

Examples

-- pair 3 4 == (3, 4)

zip : List a -> List b -> List (a, b)
zip xs ys =
    List.map2 Tuple.pair xs ys

first

first : (a, b) -> a

Extract the first value from a tuple.

Examples

first (3, 4) == 3
first ("john", "doe") == "john"

second

second : (a, b) -> b

Extract the second value from a tuple.

Examples

second (3, 4) == 4
second ("john", "doe") == "doe"

mapFirst

mapFirst : (a -> x) -> (a, b) -> (x, b)

Transform the first value in a tuple.

Examples

mapFirst String.reverse ("stressed", 16) == ("desserts", 16)
mapFirst String.length  ("stressed", 16) == (8, 16)

mapSecond

mapSecond : (b -> y) -> (a, b) -> (a, y)

Transform the second value in a tuple.

Examples

mapSecond sqrt   ("stressed", 16) == ("stressed", 4)
mapSecond negate ("stressed", 16) == ("stressed", -16)