Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ch12.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Let's rearrange our types using `sequence`:
sequence(List.of, Maybe.of(['the facts'])); // [Just('the facts')]
sequence(Task.of, new Map({ a: Task.of(1), b: Task.of(2) })); // Task(Map({ a: 1, b: 2 }))
sequence(IO.of, Either.of(IO.of('buckle my shoe'))); // IO(Right('buckle my shoe'))
sequence(Either.of, [Either.of('wing')]); // Right(['wing'])
sequence(List.of, Either.of(['wing'])); // List(Right('wing'))
sequence(Task.of, left('wing')); // Task(Left('wing'))
```

Expand Down
12 changes: 9 additions & 3 deletions support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Left extends Either {
return `Left(${inspect(this.$value)})`;
}


// ----- Functor (Either a)
map() {
return this;
Expand Down Expand Up @@ -219,7 +220,7 @@ class Right extends Either {
}

traverse(of, fn) {
fn(this.$value).map(Either.of);
return fn(this.$value).map(Either.of);
}
}

Expand Down Expand Up @@ -360,11 +361,16 @@ class Map {
.reduce((acc, k) => fn(acc, this.$value[k], k), zero);
}

// ----- Pointed Map
static of(x) {
return new Map(x);
}

// ----- Functor (Map a)
map(fn) {
return this.reduceWithKeys(
(m, v, k) => m.insert(k, fn(v)),
new Map({}),
Map.of({}),
);
}

Expand All @@ -376,7 +382,7 @@ class Map {
traverse(of, fn) {
return this.reduceWithKeys(
(f, a, k) => fn(a).map(b => m => m.insert(k, b)).ap(f),
of(new Map({})),
of(Map.of({})),
);
}
}
Expand Down
1 change: 0 additions & 1 deletion support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"guide",
"fp"
],
"dependencies": {},
"devDependencies": {
"eslint": "^5.9.0",
"eslint-config-airbnb": "^16.1.0",
Expand Down