diff --git a/README.md b/README.md index 259ff58d8..77b935eeb 100644 --- a/README.md +++ b/README.md @@ -776,7 +776,7 @@ These functions provide a very clean way to build out very simple functions and | `merge` | `(a -> b -> c) -> m a b -> c` | `crocks/Pair` | | `option` | `a -> m a -> a` | `crocks/pointfree` | | `promap` | `(c -> a) -> (b -> d) -> m a b -> m c d` | `crocks/pointfree` | -| `read` | `m a b -> a` | `crocks/Writer` | +| `read` | `m a b -> Pair a b` | `crocks/Writer` | | `reduce` | `(b -> a -> b) -> b -> m a -> b` | `crocks/pointfree` | | `reject` | ((a -> Boolean) | Pred a) -> m a -> m a | `crocks/pointfree` | | `run` | `m a -> b` | `crocks/pointfree` | diff --git a/src/Pair/writerToPair.js b/src/Pair/writerToPair.js index 391da60a7..405b26992 100644 --- a/src/Pair/writerToPair.js +++ b/src/Pair/writerToPair.js @@ -1,7 +1,6 @@ /** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ -const Pair = require('../core/Pair') const curry = require('../core/curry') const isFunction = require('../core/isFunction') @@ -9,7 +8,7 @@ const isWriter = x => !!x && isFunction(x.read) const applyTransform = w => - Pair(w.log(), w.value()) + w.read() // writerToPair : Monoid m => Writer m a -> Pair m a // writerToPair : Monoid m => (a -> Writer m a) -> Pair m b diff --git a/src/Writer/Writer.spec.js b/src/Writer/Writer.spec.js index 2bd002187..512d45ef4 100644 --- a/src/Writer/Writer.spec.js +++ b/src/Writer/Writer.spec.js @@ -5,10 +5,12 @@ const Last = require('../test/LastMonoid') const bindFunc = helpers.bindFunc +const Pair = require('../core/Pair') const curry = require('../core/curry') const compose = curry(require('../core/compose')) const isFunction = require('../core/isFunction') const isObject = require('../core/isObject') +const isSameType = require('../core/isSameType') const unit = require('../core/_unit') const identity = x => x @@ -90,10 +92,10 @@ test('Writer read', t => { const m = Writer(l, x) t.ok(isFunction(m.read), 'is a function') - t.ok(isObject(m.read()), 'returns an object') + t.ok(isSameType(Pair, m.read()), 'returns a Pair') - t.equal(m.read().value, x, 'returns the wrapped value on the value key') - t.same(m.read().log, l, 'returns unwrapped log value') + t.equal(m.read().snd(), x, 'returns the value on the value snd') + t.same(m.read().fst().value(), l, 'returns log Monoid') t.end() }) diff --git a/src/Writer/index.js b/src/Writer/index.js index c6737386b..577b51288 100644 --- a/src/Writer/index.js +++ b/src/Writer/index.js @@ -5,6 +5,7 @@ const _equals = require('../core/equals') const _implements = require('../core/implements') const _inspect = require('../core/inspect') const __type = require('../core/types').type('Writer') +const Pair = require('../core/Pair') const isFunction = require('../core/isFunction') const isMonoid = require('../core/isMonoid') @@ -47,10 +48,8 @@ function _Writer(Monoid) { const inspect = constant(`Writer(${_inspect(log())}${_inspect(value())} )`) - const read = constant({ - log: log().value(), - value: value() - }) + const read = () => + Pair(log(), val) function map(fn) { if(!isFunction(fn)) {