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.
#
writerwriter(result, output)
writer :: a -> w -> Writer (a, w)
Create a new instance of the writer monad.
Since:
bingo-functional
- v1.11.0bingo-functional-js
- v0.1.0
Argument(s):
- result - Primary monad input
- output - Ancillary log data
- JavaScript
- PHP
import { writer } from 'bingo-functional-js'
const result = writer(2, 'put 2')
use function Chemem\Bingo\Functional\Functors\Monads\Writer\writer;
$result = writer(2, 'put 2');
#
telltell(msg)
tell :: w -> m ()
Produces a Writer monad's output.
Since:
bingo-functional
- v1.11.0bingo-functional-js
- v0.1.0
Argument(s):
- msg - Writer monad output
- JavaScript
- PHP
import { tell } from 'bingo-functional-js'
const result = tell('put 2').map((x) => x + 2)
use function Chemem\Bingo\Functional\Functors\Monads\{ bind, Writer\tell};
$result = tell('put 2')->map(fn ($x): int => $x + 2);
#
runWriterrunWriter(writer)
runWriter :: Writer a w -> (a, w)
Unwraps a writer computation as a (result, output) pair.
Since:
bingo-functional
- v1.11.0bingo-functional-js
- v0.1.0
Argument(s):
- writer - Instance of Writer monad
- JavaScript
- PHP
import { writer, runWriter } from 'bingo-functional-js'
const result = writer(2, 'put 2')
runWriter(result)
use function Chemem\Bingo\Functional\Functors\Monads\Writer\{ writer, runWriter};
$result = writer(2, 'put 2');
runWriter($result);
#
execWriterexecWriter(writer)
execWriter :: Writer a w -> w
Extracts the output from a writer computation.
Since:
bingo-functional
- v1.11.0bingo-functional-js
- v0.1.0
Argument(s):
- writer - Instance of Writer monad
- JavaScript
- PHP
import { writer, execWriter } from 'bingo-functional-js'
const result = writer(2, 'put 2')
execWriter(result)
use function Chemem\Bingo\Functional\Functors\Monads\Writer\{ writer, execWriter};
$result = writer(2, 'put 2');
execWriter($result);