PHPackages                             php-fp/php-fp-reader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-fp/php-fp-reader

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

php-fp/php-fp-reader
====================

An implementation of the Reader monad in PHP.

981PHP

Since Apr 18Pushed 10y ago1 watchersCompare

[ Source](https://github.com/php-fp/php-fp-reader)[ Packagist](https://packagist.org/packages/php-fp/php-fp-reader)[ RSS](/packages/php-fp-php-fp-reader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

The Reader Monad for PHP. [![Build Status](https://camo.githubusercontent.com/66e6570a6f455949baf762b7f8efecb43430645110f783511c86f1bbd4bf387a/68747470733a2f2f7472617669732d63692e6f72672f7068702d66702f7068702d66702d7265616465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-fp/php-fp-reader)
=====================================================================================================================================================================================================================================================================================================================

[](#the-reader-monad-for-php-)

Intro
-----

[](#intro)

Sometimes, when you're composing several functions into a pipeline, there will be some value that is required by functions throughout - perhaps it's a `Request` object while creating a response in a web app. Either way, it can become messy to have to pass this in as a parameter to the functions that need it, and nearly impossible if we don't yet know its value! This is where Reader comes in.

Reader allows you to build computations that depend on a value -- known as the *environment* -- without specifying it. Then, when you wish to run the computation, you simply call `run($environment)`, and that value is available throughout the computation. You can think of this, if you really must, as type-safe dependency injection. The web server analogy is a good one: you can write your entire request lifecycle as a Reader computation, and then simply run it with each new request as a new environment! This might look something like this:

```
