temochka / enclojure / Enclojure.Value

Functions for working with Enclojure values and translating between Elm and Enclojure types.

Value type


type alias Value io =
Enclojure.Common.Value io

Represents an Enclojure value.

Inspecting values

inspect : Value io -> String

Print value in a human readable way.

inspectLocated : Enclojure.Located.Located (Value io) -> String

Prints a value with location information.

inspectType : Value io -> String

Return a string representation of the value type

isEqual : Value io -> Value io -> Basics.Bool

Returns True if the two values are equal.

isTruthy : Value io -> Basics.Bool

Returns True if the value is truthy.

Transforming values

toMap : Value io -> Maybe (Enclojure.ValueMap.ValueMap io)

Attempts to interpret a given value as a map.

toSeq : Value io -> Result Enclojure.Common.Exception (List (Enclojure.Located.Located (Value io)))

Attempts to interpret a given value as a sequence (list).

toString : Value io -> String

Attempts to intrpret a value as a string.

Encoding values

boolean : Basics.Bool -> Value io

Returns a boolean value for a given Elm Bool.

exception : String -> Enclojure.Common.Exception

Creates an exception with a given message.

float : Basics.Float -> Value io

Wraps a float as a number value.

fn : Maybe String -> Enclojure.Common.Callable io -> Value io

Wraps an (optionally named) function as a value.

int : Basics.Int -> Value io

Wraps an int as a number value.

keyword : String -> Value io

Wraps a string as a keyword value.

list : List (Value io) -> Value io

Wraps a list as a list value.

map : Enclojure.ValueMap.ValueMap io -> Value io

Wraps a value map as a map value.

nil : Value io

Returns a nil value.

string : String -> Value io

Wraps a string as a string value.

symbol : String -> Value io

Wraps a string as a symbol value.

throwable : Enclojure.Common.Exception -> Value io

Wraps an exception into a value.

vector : Array (Value io) -> Value io

Wraps an array as a vector value.

vectorFromList : List (Value io) -> Value io

Wraps a list as a vector value.

vectorFromLocatedList : List (Enclojure.Located.Located (Value io)) -> Value io

Wraps a located list as a vector value.

Decoding values

tryAtom : Value io -> Maybe Basics.Int

Returns an atom id if the given value is an atom ref.

tryBool : Value io -> Maybe Basics.Bool

Returns a bool if the given value is a string.

tryDictOf : (Value io -> Maybe comparable) -> (Value io -> Maybe b) -> Value io -> Maybe (Dict comparable b)

If the value is a map, attempts to convert it to an Elm dictionary using the first argument to convert values to keys and the second argument to convert values.

tryFloat : Value io -> Maybe Basics.Float

Returns a float if the given value is a float.

tryInt : Value io -> Maybe Basics.Int

Returns an integer if the given value is an integer.

tryKeyword : Value io -> Maybe String

Returns a keyword as a string if the given value is a keyword.

tryList : Value io -> Maybe (List (Enclojure.Located.Located (Value io)))

Returns a list of values if the given value is a list

tryListOf : (Value io -> Maybe a) -> Value io -> Maybe (List a)

If the given value is a list, returns a list of a using the first argument as a function to interpret list values as a.

tryMap : Value io -> Maybe (Enclojure.ValueMap.ValueMap io)

Returns a ValueMap io if the given value is a map.

tryNil : Value io -> Maybe ()

Returns an empty tuple if the given value is nil.

tryOneOf : List (Value io -> Maybe a) -> Value io -> Maybe a

Attempts to interpret the given value as a as one of the given "decoders".

tryPatternOf2 : (a -> b -> List (Value io) -> Maybe c) -> (Value io -> Maybe a) -> (Value io -> Maybe b) -> List (Value io) -> Maybe c

Attempts to interpret a list of values as a pattern of two values of known type and the rest.

tryRef : Value io -> Maybe (Enclojure.Common.Ref io)

Returns a ref if the given value is a ref.

tryRegex : Value io -> Maybe Regex

Returns a regex if the given value is a regex.

trySequenceOf : (Value io -> Maybe a) -> Value io -> Maybe (List a)

If the given value can be interpreted as a sequence, returns a list of a using the first argument as a function to interpret list values as a.

tryString : Value io -> Maybe String

Returns a string if the given value is a string.

trySymbol : Value io -> Maybe String

Returns a symbol as a string if the given value is a symbol.

tryVector : Value io -> Maybe (Array (Enclojure.Located.Located (Value io)))

Returns an array of values if the given value is a vector.

tryVectorOf : (Value io -> Maybe a) -> Value io -> Maybe (List a)

If the given value is a vector, returns a list of a using the first argument as a function to interpret vector values as a.