Skip to content

Commit

Permalink
have read return a Pair for Writer (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsoft authored Nov 8, 2017
1 parent 34e7e2e commit 5f13597
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | <code>((a -> Boolean) &#124; Pred a) -> m a -> m a</code> | `crocks/pointfree` |
| `run` | `m a -> b` | `crocks/pointfree` |
Expand Down
3 changes: 1 addition & 2 deletions src/Pair/writerToPair.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/** @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')

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
Expand Down
8 changes: 5 additions & 3 deletions src/Writer/Writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
})
Expand Down
7 changes: 3 additions & 4 deletions src/Writer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 5f13597

Please sign in to comment.