This library provides utility functions for working with nested tuples of the form:
( a, ( b, ( c, () ) ) ).
Prepend a value to a nested tuple.
Get the head (first element) of a nested tuple.
Get the tail (everything except the first element) of a nested tuple.
Note: From the four primitive functions empty, cons, head and tail, all the
others can be derived.
In your own project, you might want to represent a nested tuple as something other than a tuple, for example:
type alias MyTuple a b = { head : a, tail : b }type MyTuple a b = MyTuple a bIf so, you could just vendor this package and redefine these four functions for your preferred data type, then delete all the type annotations, and everything else should just work.
Create a nested tuple with one element.
Map over the head of a nested tuple.
Map over the tail of a nested tuple.
Begin the definition of an appender, mapper, or folder.
Build up a nested tuple by appending values to the end of it.
This needs to be used in conjunction with define and endAppender:
import NestedTuple exposing (define, appender, endAppender)
define
|> appender 1
|> endAppender
--> ( 1, () )
define
|> appender "hello"
|> appender "world"
|> endAppender
--> ( "hello", ( "world", () ) )Complete the definition of an appender.
Create a mapper for a nested tuple by defining a map functions for each element of the tuple.
This needs to be used in conjunction with define and endMapper:
import NestedTuple exposing (define, mapper, endMapper)
double =
define
|> mapper (\int -> int * 2)
|> mapper (\float -> float + float)
|> endMapper
double ( 1, ( 1.5, () ) )
--> ( 2, ( 3.0, () ) )Complete the definition of a mapper.
Create a mapper for two nested tuples by defining map functions for each element of the tuples.
This needs to be used in conjunction with define and endMapper2:
import NestedTuple exposing (define, mapper2, endMapper2)
add =
define
|> mapper2 (\int1 int2 -> int1 + int2)
|> mapper2 (\float1 float2 -> float1 + float2)
|> endMapper2
add ( 1, ( 1.5, () ) )
( 2, ( 2.5, () ) )
--> ( 3, ( 4.0, () ) )Complete the definition of a mapper2.
Create a mapper for three nested tuples by defining map functions for each element of the tuples.
This needs to be used in conjunction with define and endMapper3:
import NestedTuple exposing (define, mapper3, endMapper3)
add =
define
|> mapper3 (\int1 int2 int3 -> int1 + int2 + int3)
|> mapper3 (\float1 float2 float3 -> float1 + float2 + float3)
|> endMapper3
add ( 1, ( 1.5, () ) )
( 2, ( 2.5, () ) )
( 3, ( 3.5, () ) )
--> ( 6, ( 7.5, () ) )Complete the definition of a mapper3.
Create a folder for a nested tuple by defining fold functions for each element of the tuple.
This needs to be used in conjunction with define and endFolder:
import NestedTuple exposing (define, folder, endFolder)
sum =
define
|> folder (\int acc -> int + acc)
|> folder (\str acc -> String.length str + acc)
|> endFolder
sum 0 ( 1, ( "foo", () ) )
--> 4Complete the definition of a folder.
Create a folder2 for two nested tuples by defining fold functions for each element of the tuples.
This needs to be used in conjunction with define and endFolder2:
import NestedTuple exposing (define, folder2, endFolder2)
sum =
define
|> folder2 (\int1 int2 acc -> int1 + int2 + acc)
|> folder2 (\str1 str2 acc -> String.length (str1 ++ str2) + acc)
|> endFolder2
sum 0
( 1, ( "foo", () ) )
( 2, ( "bar", () ) )
--> 9Complete the definition of a folder2.
Create a folder3 for three nested tuples by defining fold functions for each element of the tuples.
This needs to be used in conjunction with define and endFolder3:
import NestedTuple exposing (define, folder3, endFolder3)
sum =
define
|> folder3 (\int1 int2 int3 acc -> int1 + int2 + int3 + acc)
|> folder3 (\str1 str2 str3 acc -> String.length (str1 ++ str2 ++ str3) + acc)
|> endFolder3
sum 0
( 1, ( "foo", () ) )
( 2, ( "bar", () ) )
( 3, ( "baz", () ) )
--> 15Complete the definition of a folder3.
Begin the definition of a tuple of getters.
Create a tuple of getters for a nested tuple.
This needs to be used in conjunction with defineGetters and endGetters:
import NestedTuple exposing (defineGetters, getter, endGetters)
defineGetters
|> getter
|> getter
|> endGetters
--: ( ( a, ( b, () ) ) -> a
, ( ( a, ( b, () ) ) -> b
, ()
)
)Complete the definition of a tuple of getters.
Begin the definition of a tuple of setters.
Create a tuple of setters for a nested tuple.
This needs to be used in conjunction with defineSetters and endSetters:
import NestedTuple exposing (defineSetters, setter, endSetters)
defineSetters
|> setter
|> setter
|> endSetters
--: ( a -> ( a, ( b, () ) ) -> ( a, ( b, () ) )
, ( b -> ( a, ( b, () ) ) -> ( a, ( b, () ) )
, ()
)
)Complete the definition of a tuple of setters.
Create an empty nested tuple.