espresso - Purely Functional Expression DSL Builder Library
For building DSLs that allow the composition of pure and fully type-safe expressions such that any sub-expression may generate or receive errors as input, short-circuiting evaluation.
Ordering an espresso
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
libraryDependencies ++= Seq(
"io.nary" %% "espresso" % "0.0.1"
)
espresso makes extensive use of the Typelevel cats and shapeless libraries as well as the kind-projector compiler plugin.
Sample expression syntax and library
Take a look at https://github.com/ryanonsrc/espresso/tree/master/src/test/scala/io/nary/espresso/sample
Fundamental units of composition
Term[E, A]
- Represents a term within an expression, evaluating to an error of typeE
or result of typeA
Expr[E, A, B]
- For any expression taking a value of typeA
and evaluating to either a result of typeB
or an error of typeE
In[E, A]
- Input that can be "read" into an expression as either value of typeA
or an error of typeE
opN
- Lift a function f: (HList ofN
terms ⇒Term[E, B]
) into aExpr[E, A1 :: ... :: AN :: HNil, B]
joinN
- Combine an Hlist ofN
expressions:Expr[E, A, Bi]
into a singleExpr[E, A, B1 :: ... :: BN :: HNil]
evalN
- GivenN
expressions:Expr[E, A, Bi]
and operation:Expr[E, B1 :: ... :: BN :: HNil, C]
, generateExpr[E, A, C]