ccapndave/elm-eexl/1.0.0

Eexl.Context

This module manages the context that an expression runs with. Specifically it is used to assign values to constants, and set functions that can be called from the expression.

context : Context
context =
    Context.empty
        |> Context.addConstant "x" 5
        |> Context.addFunction "stringToInt" stringToInt




Eexl.evaluateInt context """x + 5 + stringToInt("7")""" -- = Ok 17

Definition

type Context

This is the type of Context that is passed into the functions that evaluate expressions.

Creation

An empty context containing no functions or constants.

Adding constants and functions

addConstant : String -> Int -> Context -> Context

Add a constant to the context.

addFunction : String -> (String -> Int) -> Context -> Context

Add a function to the context.

Reading constants and function

getConstant : String -> Context -> Maybe Int

Retrieve a constant from the context (not usually used).

getFunction : String -> Context -> Maybe (String -> Int)

Retrieve a constant from the context (not usually used).