Skip to content

Commit 2aad933

Browse files
committed
Fix hack with List.js
1 parent fa29c6f commit 2aad933

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { Either, either, left, fromNullable } = require('./src/either')
2+
const { List } = require('./src/list')
23

34
const id = _ => _
45
const always = a => () => a
@@ -12,7 +13,7 @@ const DEFAULTS = {
1213
}
1314

1415
/* --- Functional Utilities --- */
15-
const map = fn => x => (x.map ? x.map(fn) : fn(x)) // FIXME remove check
16+
const map = fn => x => x.map(fn)
1617
const join = m => m.join()
1718
// const chain = fn => m => m.chain(fn)
1819
const compose = (...fns) => (res, ...args) =>
@@ -29,6 +30,8 @@ const createRootObj = compose(
2930
Number
3031
)
3132

33+
const handleArrays = _ => (Array.isArray(_) ? List.of(_) : Either.of(_))
34+
3235
const normalizeField = delimiter => m =>
3336
fromNullable(m)
3437
.map(m => m.indexOf(delimiter) > -1)
@@ -96,7 +99,9 @@ class Mapper {
9699
.chain(getMapSpec(this.config.mapDelimiter))
97100
.chain(([sourceField, targetField]) =>
98101
Either.of(sourceField)
102+
.map(handleArrays)
99103
.map(map(field => get(field, this.config.objDelimiter)(curr)))
104+
.map(join)
100105
.map(_ =>
101106
compose(
102107
/* End user-land transforms */

src/list.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class List {
2+
constructor(xs) {
3+
this._ = xs
4+
this.concat = x => new List(xs.concat(x))
5+
// ----- Functor List
6+
this.map = fn => new List(xs.map(fn))
7+
this.chain = fn => xs.map(fn)
8+
this.join = () => xs
9+
}
10+
// inspect() { return `List(${inspect(this._)})` }
11+
// ----- Traversable List
12+
// sequence(of) { return this.traverse(of, identity); }
13+
// traverse(of, fn) {
14+
// return this._.reduce(
15+
// (f, a) => fn(a).map(b => bs => bs.concat(b)).ap(f),
16+
// of(new List([])),
17+
// );
18+
// }
19+
}
20+
21+
// ----- Pointed List
22+
List.of = xs => new List(xs)
23+
24+
module.exports = {
25+
List
26+
}

0 commit comments

Comments
 (0)