Convenience functions for working with tuples.
Tuple functions for 3-tuplesExtract the second value from a 3-tuple.
second ( 3, 4, 5 ) --> 4
second ( "John", "H.", "Doe" ) --> "H."Extract the third value from a 3-tuple.
third ( 3, 4, 5 ) --> 5
third ( "John", "H.", "Doe" ) --> "Doe"Transform the first value in a 3-tuple.
mapFirst String.reverse ( "stressed", 16, 1 ) --> ( "desserts", 16, 1 )
mapFirst String.length ( "stressed", 16, 1 ) --> ( 8, 16, 1 )Transform the second value in a 3-tuple.
mapSecond sqrt ( "stressed", 16, 1 ) --> ( "stressed", 4, 1 )
mapSecond negate ( "stressed", 16, 1 ) --> ( "stressed", -16, 1 )Transform the second value in a 3-tuple.
mapThird (List.repeat 2) ( "stressed", 16, 1 ) --> ( "stressed", 16, [1, 1] )
mapThird String.fromInt ( "stressed", 16, 1 ) --> ( "stressed", 16, "1" )Transform all three parts of a 3-tuple.
mapAllThree String.reverse sqrt List.length ( "stressed", 16, [] ) --> ( "desserts", 4, 0 )
mapAllThree String.length negate List.isEmpty ( "stressed", 16, [] ) --> ( 8, -16, True )Create a 3-tuple with three values.
join 1 2 3 --> ( 1, 2, 3 )Create a 3-tuple with three values.
1 |> joinTo 2 3
--> ( 1, 2, 3 )Create a 3-tuple with the same value.
triple 0
--> ( 0, 0, 0 )Create a 3-tuple from a 2-tuple with a 2-tuple.
splitFirst ( ( 1, 2 ), 3 ) --> ( 1, 2, 3 )Create a 3-tuple from a 2-tuple with a 2-tuple.
splitSecond ( 1, ( 2, 3 ) ) --> ( 1, 2, 3 )Reverse values in a 3-tuple.
reverse ( 1, 2, 3 ) --> ( 3, 2, 1 )Rotate values in 3-tuple to the left.
rotateLeft ( 1, 2, 3 ) --> ( 2, 3, 1 )Rotate values in 3-tuple to the right.
rotateRight ( 1, 2, 3 ) --> ( 3, 1, 2 )Swap first two values in a 3-tuple.
swapFirst ( 1, 2, 3 ) --> ( 2, 1, 3 )Swap last two values in a 3-tuple.
swapLast ( 1, 2, 3 ) --> ( 1, 3, 2 )Apply each value in a 3-tuple to a function that takes at least 3 arguments.
type alias Person =
{ name : String
, age : Int
, hobbies : List String
}
uncurry Person ( "John Doe", 34, ["Hockey"] )
--> { name = "John Doe", age = 34, hobbies = [ "Hockey" ] }Apply the second and third values in a 3-tuple to the first.
apply (String.cons, 'H', "ello")
--> "Hello"Apply a function that returns a Maybe to the first value in a 3-tuple. If
it returns Just something, join the second and third values back with it.
("1", "hit", "wonder")
|> maybeMapFirst String.toInt
--> Just (1, "hit", "wonder")
("One", "hit", "wonder")
|> maybeMapFirst String.toInt
--> NothingApply a function that returns a Maybe to the second value in a 3-tuple. If
it returns Just something, join the first and third values back with it.
(1, "hit", "wonder")
|> maybeMapSecond String.uncons
--> Just (1, ('h', "it"), "wonder")
(1, "hit", "wonder")
|> maybeMapSecond String.toInt
--> NothingApply a function that returns a Maybe to the third value in a 3-tuple. If
it returns Just something, join the first and second values back with it.
(1, "hit", "wonder")
|> maybeMapThird String.uncons
--> Just (1, "hit", ('w', "onder"))
(1, "hit", "wonder")
|> maybeMapThird String.toInt
--> Nothing
Extract the first value from a 3-tuple.