Interpreter is a language (or program) to evaluate expressions and execute code. The intent is to keep the evaluation lazy and pure.
There are 3 different kinds of methods in the interpreter pattern / Algebra:
Constructors
- Takes something that is not an algebra type (not a
Response) and produces aResponse - Usually found on the companion object
- E.g.
Response.ok: takes something that is not aResponse(anEntity) and produces aResponse(Entity => Response)
Combinators
- Takes an algebra (
Response) and some other stuff (which may be an algebra /Responseor something else entirely) and produces aResponse/ algebra orNotFound: Response[A] => Response[Option[A]]- Build up more complex descriptions of what we want to do
Interpreters
- Takes an algebra (a
Response) and produces something else (anIO[Http4sResponse[IO]]) - E.g.
respondmethod - Does the actual work we have described in the algebra /
Response