danielnarey/elm-toolkit/6.1.0

NOTE: this package is not compatible with Elm 0.19.1

Toolkit.List

General

isOneOf : List a -> a -> Bool

Given a list and a test value, returns True if the list contains a value equal to the test value.

Equivalent to List.member with the arguments flipped

getNth : Int -> List a -> Maybe a

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

getNth 0 [1, 3, 9, 27]    --> Just 1
getNth 3 [1, 3, 9, 27]    --> Just 27
getNth 4 [1, 3, 9, 27]    --> Nothing
getNth -1 [1, 3, 9, 27]   --> Nothing
unique : List comparable -> List comparable

Given a list of values, returns the unique values as a list sorted from highest to lowest

List-Tuple conversions

take2Tuple : List a -> Maybe ( a, a )

Returns the first two items in a list as a 2-tuple, or Nothing if the list contains fewer than two items

take2Tuple [1,2]    --> Just (1,2)
take2Tuple [1,2,3]  --> Just (1,2)
take2Tuple [1]      --> Nothing
take3Tuple : List a -> Maybe ( a, a, a )

Returns the first three items in a list as a 3-tuple, or Nothing if the list contains fewer than three items

take4Tuple : List a -> Maybe ( a, a, a, a )

Returns the first four items in a list as a 4-tuple, or Nothing if the list contains fewer than four items

from2Tuple : ( a, a ) -> List a

Given a 2-tuple where both values are of the same type, return a list containing those values

from3Tuple : ( a, a, a ) -> List a

Given a 3-tuple where all three values are of the same type, return a list containing those values

from4Tuple : ( a, a, a, a ) -> List a

Given a 4-tuple where all four values are of the same type, return a list containing those values

Zipping and unzipping

zip : ( List a, List b ) -> List ( a, b )

Convert a 2-tuple of lists to a list of 2-tuples

zip ([0,17,1337], [True,False,True])


--> [(0, True), (17, False), (1337, True)]
zip3 : ( List a, List b, List c ) -> List ( a, b, c )

Convert a 3-tuple of lists to a list of 3-tuples

zip4 : ( List a, List b, List c, List d ) -> List ( a, b, c, d )

Convert a 4-tuple of lists to a list of 4-tuples

unzip3 : List ( a, b, c ) -> ( List a, List b, List c )

Convert a 3-tuple of lists to a list of 3-tuples (see List.unzip)

unzip4 : List ( a, b, c, d ) -> ( List a, List b, List c, List d )

Convert a 4-tuple of lists to a list of 4-tuples