Skip to main content

Writer

The Writer monad is one that has - in addition to a transformable value in its monadic context - a log proviso. It allows for accumulation of logs throughout multiple computations.

writer#

writer(result, output)

writer :: a -> w -> Writer (a, w)

Create a new instance of the writer monad.

Since:

  • bingo-functional - v1.11.0
  • bingo-functional-js - v0.1.0

Argument(s):

  • result - Primary monad input
  • output - Ancillary log data
use function Chemem\Bingo\Functional\Functors\Monads\Writer\writer;
$result = writer(2, 'put 2');

tell#

tell(msg)

tell :: w -> m ()

Produces a Writer monad's output.

Since:

  • bingo-functional - v1.11.0
  • bingo-functional-js - v0.1.0

Argument(s):

  • msg - Writer monad output
use function Chemem\Bingo\Functional\Functors\Monads\{  bind,  Writer\tell};
$result = tell('put 2')->map(fn ($x): int => $x + 2);

runWriter#

runWriter(writer)

runWriter :: Writer a w -> (a, w)

Unwraps a writer computation as a (result, output) pair.

Since:

  • bingo-functional - v1.11.0
  • bingo-functional-js - v0.1.0

Argument(s):

  • writer - Instance of Writer monad
use function Chemem\Bingo\Functional\Functors\Monads\Writer\{  writer,  runWriter};
$result = writer(2, 'put 2');
runWriter($result);

execWriter#

execWriter(writer)

execWriter :: Writer a w -> w

Extracts the output from a writer computation.

Since:

  • bingo-functional - v1.11.0
  • bingo-functional-js - v0.1.0

Argument(s):

  • writer - Instance of Writer monad
use function Chemem\Bingo\Functional\Functors\Monads\Writer\{  writer,  execWriter};
$result = writer(2, 'put 2');
execWriter($result);