Skip to content

Commit a12afe6

Browse files
committed
Use map instead of compose
1 parent d499622 commit a12afe6

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,26 @@ class Mapper {
9090
Maybe.of(mapping.field)
9191
.chain(getMapSpec(this.config.mapDelimiter))
9292
.chain(([sourceField, targetField]) =>
93-
compose(
94-
maybe(accum)(
95-
assign(targetField, this.config.objDelimiter).bind(this, accum)
96-
),
97-
Maybe.of,
98-
/* End user-land transforms */
99-
...this.config.postFilters,
100-
getMappingFilter(mapping.type, this.config.types),
101-
...this.config.preFilters,
102-
/* Begin user-land transforms */
103-
map(field => get(field, this.config.objDelimiter)(curr))
104-
/* Fields passed to user functions */
105-
)(sourceField, mapping, this.config, curr, accum)
93+
Either.of(sourceField)
94+
.map(map(field => get(field, this.config.objDelimiter)(curr)))
95+
.map(_ =>
96+
compose(
97+
/* End user-land transforms */
98+
...this.config.postFilters,
99+
getMappingFilter(mapping.type, this.config.types),
100+
...this.config.preFilters
101+
/* Begin user-land transforms */
102+
)(_, mapping, this.config, curr, accum)
103+
)
104+
.map(Maybe.of)
105+
.chain(
106+
maybe(accum)(
107+
assign(targetField, this.config.objDelimiter).bind(
108+
this,
109+
accum
110+
)
111+
)
112+
)
106113
),
107114
next
108115
)

src/either.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Left extends Either {
1212
// ----- Functor (Either a)
1313
this.map = () => this
1414
this.join = this.map
15+
// ----- Monad (Either a)
16+
this.chain = () => this
1517
}
1618
// ----- Applicative (Either a)
1719
// ap() { return this }
18-
// ----- Monad (Either a)
19-
// chain() { return this }
2020
// inspect() { return `Left(${this._})` }
2121
// ----- Traversable (Either a)
2222
// sequence(of) { return of(this) }
@@ -32,11 +32,11 @@ class Right extends Either {
3232
// ----- Functor (Either a)
3333
this.map = fn => Either.of(fn(x))
3434
this.join = () => x
35+
// ----- Monad (Either a)
36+
this.chain = fn => fn(x)
3537
}
3638
// ----- Applicative (Either a)
3739
// ap(f) { return f.map(this._) }
38-
// ----- Monad (Either a)
39-
// chain(fn) { return fn(this._) }
4040
// inspect() { return `Right(${this._})` }
4141
// ----- Traversable (Either a)
4242
// sequence(of) { return this.traverse(of, identity) }

0 commit comments

Comments
 (0)