TheReader
monad (also called the Environment monad), represents a computation, which can read values from a shared environment, pass values from function to function, and execute sub-computations in a modified environment. [...]
createServer
function which prepares underneath a basic application context with default set of bounded dependencies, like, eg. Logger.ContextReader
interface, which in other words means that the registered function should be able to read from the bootstrapped server context. Knowing the basics, let's create some readers!GET /
request, you should see in the Hello, world!
message in the response. Thats how Dependency Injection work in Marble.js!EffectContext
which holds i.a. the context provider (ask) and the contextual client instance (in case of HTTP module it will be a running HttpServer).Dependency2Token
, we can also grab the dependency inferred type. Reading from the context is not a safe operation, thus the provided dependency is wrapped around Option monad that you can work on. As you can see the real benefit of using Readers is to be able to provide that context in an implicit way without the need to state it explicitly on each one of the functions that needs it.createReader
and useContext
utility functions that save a lot of unnecessary boilerplate. Let's redefine the previous example.bindEagerlyTo
function. It means that the registered dependency will try to resolve its dependencies on server startup.