bundsol/boxed/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Boxed.Lst

A couple of well known tools carried over from the List module, and others derived from it. Since the members of a list are Boxed, all of them can be encapsulations of values of different types.

Unboxing

mapHead : (Boxed c -> Maybe a) -> Boxed c -> Maybe a

Returns the first member of a boxed list, only if it could be transformed into a different value.

mapHead asInt (Lst [Integer 1, Str "b", Double 3.01]) == Just 1
--It was decided that integers can become floats
mapHead asFloat (Lst [Integer 1, Str "b", Double 3.01]) == Just 1
mapHead asString (Lst [Integer 1, Str "b", Double 3.01]) == Nothing
mapFind : (Boxed c -> Maybe a) -> Boxed c -> Maybe a

Finds a member in a boxed list, only if it could be transformed into a different value.

mapFind asString (Lst [Integer 1, Str "b", Double 3.01]) == Just "b"
mapFind asBool (Lst [Integer 1, Str "b", Double 3.01]) == Nothing
filterMap : (Boxed c -> Maybe a) -> Boxed c -> List a

Returns only succesful values, resulting from the application of a given function.

filterMap asFloat (Lst [Integer 1, Str "b", Double 3.01]) == [1,3.01]
filterMap asBool (Lst [Integer 1, Str "b", Double 3.01]) == []
filterMap asBool (Double 3.01) == []
foldr : (Boxed c -> a -> a) -> a -> Boxed c -> a

Reduce a boxed list from the right.

foldl : (Boxed c -> a -> a) -> a -> Boxed c -> a

Reduce a boxed list from the left.

Putting Lists Together

(:::) : Boxed c -> Boxed c -> Boxed c

Adds an element to the front of a Boxed list. The encapsulated value of the new member does not need to be of the same type as the rest.

(Integer 1) ::: (Lst [Str "b", Double 3.03]) == Lst [Integer 1, Str "b", Double 3.03]
(Integer 1) ::: (Lst []) == Lst [Integer 1]
(Integer 1) ::: (Str "d") == Lst [Integer 1]

Extraction

find : (Boxed c -> Bool) -> Boxed c -> Maybe (Boxed c)

Finds, inside a list, a 'Boxed' that passes a given test.

 find isString (Lst [Integer 1, Str "b", Double 3.01]) == Just (Str "b")
 find isTuple (Lst [Integer 1, Str "b", Double 3.01]) == Nothing
 find isNull (Lst [Integer 1, Null, Double 3.01]) == Just Null

Mapping

apply : (List (Boxed c) -> a) -> Boxed c -> a

Apply a given function to a boxed list.

apply List.head (Lst [Integer 1, Str "b", Double 3.03]) == Just (Integer 1)
apply List.tail (Lst [Integer 1, Str "b", Double 3.03]) == Just [Str "b", Double 3.03]
apply (List.member (Str "b")) (Lst [Integer 1, Str "b", Double 3.03]) == True
apply (List.map asInt) (Lst [Integer 1, Str "b", Double 3.03]) == [Just 1,Nothing,Nothing]