bundsol/boxed/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Boxed

This library allows a variable to hold a value of any type. The name of the module is derived from the Autoboxing concept in Java. Boxed values can be useful when receiving external data that you do not want to thoroughly check for errors, but rather disregard the type of some of the values obtained. For example, you might be more interested in the structure of the received data than the type of all of the member values. The decoder found at Boxed.Json lets any kind of value through, allowing you to focus on the shape of the whole data structure.

Some helper functions are provided to extract native Elm values, for example:

filterMap asFloat (Lst [Integer 1, Str "b", Double 3.01]) 
-- It returns [1,3.01]

Note: Dict has been limited to use only String as keys

Definition

type Boxed c
= Null
| Boolean Bool
| Integer Int
| Double Float
| Str String
| Json Value
| Lst (List (Boxed c))
| Dictionary (Dict String (Boxed c))
| Tup ( Boxed c, Boxed c )
| Custom c

Unboxing

Return value of the indicated type only if given Boxed is currently holding an encapsulation of said type. (Exception made on asFloat).

asBool : Boxed c -> Maybe Bool
asFloat : Boxed c -> Maybe Float

Note: Both Integer and Double will be able to pass as Float

asInt : Boxed c -> Maybe Int
asString : Boxed c -> Maybe String
asValue : Boxed c -> Maybe Value
asList : Boxed c -> List (Boxed c)

Always returns a List. Consider using it along with isList.

asDict : Boxed c -> Dict String (Boxed c)

Always returns a Dict. Consider using it along with isDict.

isTrue : Boxed c -> Bool

Return value of boxed Bool. If Boxed is holding any other type, return False.

Query

Functions to determine the type currently encapsulated.

isBool : Boxed c -> Bool
isFloat : Boxed c -> Bool
isInt : Boxed c -> Bool
isString : Boxed c -> Bool
isValue : Boxed c -> Bool
isList : Boxed c -> Bool
isDict : Boxed c -> Bool
isTuple : Boxed c -> Bool
isCustom : Boxed c -> Bool
isNull : Boxed c -> Bool