Helpers for working with lists
Get the value at the nth place of a list without converting the list to an
array; returns Nothing if the list contains fewer than n + 1 items, or if
n is negative
[1, 3, 9, 27]
|> Toolkit.List.getNth 0
--> Just 1
[1, 3, 9, 27]
|> Toolkit.List.getNth 3
--> Just 27
[1, 3, 9, 27]
|> Toolkit.List.getNth 4
--> Nothing
[1, 3, 9, 27]
|> Toolkit.List.getNth -1
--> NothingGiven a list of values, returns the unique values as a list sorted from highest to lowest
[ "banana"
, "cherry"
, "apple"
, "apple"
]
|> Toolkit.List.unique
--> ["apple", "banana", "cherry"]Returns the first two items in a list as a 2-tuple, or Nothing if the list
contains fewer than two items
[1,2]
|> Toolkit.List.take2Tuple
--> Just (1,2)
[1,2,3]
|> Toolkit.List.take2Tuple
--> Just (1,2)
[1]
|> Toolkit.List.take2Tuple
--> NothingReturns the first three items in a list as a 3-tuple, or Nothing if the
list contains fewer than three items
Returns the first four items in a list as a 4-tuple, or Nothing if the
list contains fewer than four items
Given a 2-tuple where both values are of the same type, return a list containing those values
(1,2)
|> Toolkit.List.from2Tuple
--> Just [1,2]Given a 3-tuple where all three values are of the same type, return a list containing those values
Given a 4-tuple where all four values are of the same type, return a list containing those values
Convert a 2-tuple of lists to a list of 2-tuples
( [ 0
, 17
, 1337
]
, [ True
, False
, True
]
)
|> Toolkit.List.zip
--> [(0, True), (17, False), (1337, True)]Convert a 3-tuple of lists to a list of 3-tuples
Convert a 4-tuple of lists to a list of 4-tuples
Convert a 3-tuple of lists to a list of 3-tuples (see List.unzip)
Convert a 4-tuple of lists to a list of 4-tuples
Given a list and a test value, returns
Trueif the list contains a value equal to the test value.Equivalent to List.member with the arguments flipped