ccapndave / elm-eexl / 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

empty : Context

An empty context containing no functions or constants.

Adding constants and functions

addConstant : String -> Basics.Int -> Context -> Context

Add a constant to the context.

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

Add a function to the context.

Reading constants and function

getConstant : String -> Context -> Maybe Basics.Int

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

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

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