Skip to content

Commit cd2250f

Browse files
committed
Remove identity.js
1 parent 5acafe9 commit cd2250f

4 files changed

Lines changed: 12 additions & 34 deletions

File tree

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const { Identity, id } = require('./src/identity')
21
const { Maybe, maybe } = require('./src/maybe')
3-
const { Right, Left, either } = require('./src/either')
2+
const { Either, either, left } = require('./src/either')
3+
4+
const id = _ => _
45

56
const DEFAULTS = {
67
types: {},
@@ -31,18 +32,18 @@ const normalizeField = delimiter =>
3132
compose(
3233
join,
3334
chain(m =>
34-
Identity.of(m)
35+
Maybe.of(m)
3536
.map(m => m.indexOf(delimiter) > -1)
3637
.map(b => (b ? m : m + delimiter + m))
3738
.map(split(delimiter))
3839
),
39-
Identity.of
40+
Maybe.of
4041
)
4142

4243
const getMapSpec = (mapping, delimiter) =>
43-
Identity.of(mapping)
44+
Maybe.of(mapping)
4445
.map(Array.isArray)
45-
.map(b => (b ? new Right(mapping) : new Left(mapping)))
46+
.map(b => (b ? Either.of(mapping) : left(mapping)))
4647
.map(
4748
either(
4849
normalizeField(delimiter),

src/either.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class Right extends Either {
4747
Either.of = x => new Right(x)
4848

4949
const either = (f, g) => e => (e.isLeft ? f(e._) : g(e._))
50+
const left = x => new Left(x)
5051

5152
module.exports = {
5253
Either,
53-
Right,
54-
Left,
55-
either
54+
either,
55+
left
5656
}

src/identity.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/maybe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class Maybe {
55
// ----- Functor Maybe
66
this.map = fn => (this.nil ? this : Maybe.of(fn(x)))
77
this.join = () => (this.nil ? this : x)
8+
// ----- Monad Maybe
9+
this.chain = fn => this.map(fn).join()
810
}
911
// inspect() { return `Maybe(${this._}`; }
1012
// ----- Applicative Maybe
1113
// ap(f) { return this.nil ? this : f.map(this._) }
12-
// ----- Monad Maybe
13-
// chain(fn) { return this.map(fn).join() }
1414
// ----- Traversable Maybe
1515
// sequence(of) { this.traverse(of, identity) }
1616
// traverse(of, fn) { return this.nil ? of(this) : fn(this._).map(Maybe.of) }

0 commit comments

Comments
 (0)