Skip to content

Commit dbcfe09

Browse files
Add alt combinator and update documentation
1 parent 7feb5ca commit dbcfe09

11 files changed

Lines changed: 84 additions & 46 deletions

File tree

.github/document.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export FL_DESCRIPTION="Common Functional Programming Algebraic data types for Ja
33
modern browsers and Deno."
44
export FL_GITHUB_URL="https://github.com/sebastienfilion/functional"
55
export FL_DENO_URL="https://deno.land/x/functional"
6-
export FL_VERSION="v1.3.1"
6+
export FL_VERSION="v1.3.2"
77

88
deno run --allow-all --unstable ../@functional:generate-documentation/cli.js document \
99
"$FL_TITLE" \

.github/readme-fragment-typescript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
Task,
1212
factorizeType,
1313
factorySumType
14-
} from "https://deno.land/x/functional@v1.3.0/mod.ts";
14+
} from "https://deno.land/x/functional@v1.3.2/mod.ts";
1515
```
1616

1717
Or, you can import individual sub-module with the appropriate TypeScript hint in Deno.
1818

1919
```ts
20-
// @deno-types="https://deno.land/x/functional@v1.3.0/library/Either.d.ts"
21-
import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
20+
// @deno-types="https://deno.land/x/functional@v1.3.2/library/Either.d.ts"
21+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
2222
```
2323

.github/readme-fragment-usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ the [Fantasy-land specifications](https://github.com/fantasyland/fantasy-land).
55

66
```js
77
import { compose, converge, curry, map, prop } from "https://deno.land/x/ramda@v0.27.2/mod.ts";
8-
import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
9-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
8+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
9+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
1010

1111
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
1212

@@ -44,7 +44,7 @@ As a convenience, when using Functional in the browser, you can use the **unmini
4444

4545
```js
4646
import { compose, converge, lift, map, prop } from "https://deno.land/x/ramda@v0.27.2/mod.ts";
47-
import { Either, Task } from "https://deno.land/x/functional@v1.3.0/functional.js";
47+
import { Either, Task } from "https://deno.land/x/functional@v1.3.2/functional.js";
4848

4949
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
5050

README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Common Functional Programming Algebraic data types for JavaScript that is compatible with most modern browsers and Deno.
44

5-
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno&labelColor=black)](https://deno.land/x/functional@v1.3.1)
5+
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno&labelColor=black)](https://deno.land/x/functional@v1.3.2)
66
[![deno version](https://img.shields.io/badge/deno-^1.6.1-lightgrey?logo=deno)](https://github.com/denoland/deno)
77
[![GitHub release](https://img.shields.io/github/v/release/sebastienfilion/functional)](https://github.com/sebastienfilion/functional/releases)
8-
[![GitHub licence](https://img.shields.io/github/license/sebastienfilion/functional)](https://github.com/sebastienfilion/functional/blob/v1.3.1/LICENSE)
8+
[![GitHub licence](https://img.shields.io/github/license/sebastienfilion/functional)](https://github.com/sebastienfilion/functional/blob/v1.3.2/LICENSE)
99

1010
* [Either](#either)
1111
* [IO](#io)
@@ -24,8 +24,8 @@ the [Fantasy-land specifications](https://github.com/fantasyland/fantasy-land).
2424

2525
```js
2626
import { compose, converge, curry, map, prop } from "https://deno.land/x/ramda@v0.27.2/mod.ts";
27-
import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
28-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
27+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
28+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
2929

3030
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
3131

@@ -59,11 +59,11 @@ sayHello(userID).run()
5959

6060
### Using the bundle
6161

62-
As a convenience, when using Functional in the browser, you can use the **unminified** bundled copy.
62+
As a convenience, when using Functional in the browser, you can use the **unminified** bundled copy (18KB gzipped).
6363

6464
```js
6565
import { compose, converge, lift, map, prop } from "https://deno.land/x/ramda@v0.27.2/mod.ts";
66-
import { Either, Task } from "https://deno.land/x/functional@v1.3.0/functional.js";
66+
import { Either, Task } from "https://deno.land/x/functional@v1.3.2/functional.js";
6767

6868
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
6969

@@ -96,7 +96,7 @@ The `Either` type implements the following algebras:
9696
### Example
9797

9898
```js
99-
import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
99+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
100100

101101
const containerA = Either.Right(42).map(x => x + 2);
102102
const containerB = Either.Left(new Error("The value is not 42.")).map(x => x + 2);
@@ -126,7 +126,7 @@ The `IO` type implements the following algebras:
126126
### Example
127127

128128
```js
129-
import IO from "https://deno.land/x/functional@v1.3.0/library/IO.js";
129+
import IO from "https://deno.land/x/functional@v1.3.2/library/IO.js";
130130

131131
const container = IO(_ => readFile(`${Deno.cwd()}/dump/hoge`))
132132
.map(promise => promise.then(text => text.split("\n")));
@@ -154,7 +154,7 @@ The `Maybe` type implements the following algebras:
154154
### Example
155155

156156
```js
157-
import Maybe from "https://deno.land/x/functional@v1.3.0/library/Maybe.js";
157+
import Maybe from "https://deno.land/x/functional@v1.3.2/library/Maybe.js";
158158

159159
const containerA = Maybe.Just(42).map(x => x + 2);
160160
const containerB = Maybe.Nothing.map(x => x + 2);
@@ -181,7 +181,7 @@ The `Pair` type implements the following algebras:
181181
### Example
182182

183183
```js
184-
import Pair from "https://deno.land/x/functional@v1.3.0/library/Pair.js";
184+
import Pair from "https://deno.land/x/functional@v1.3.2/library/Pair.js";
185185

186186
const pair = Pair(42, 42)
187187
.bimap(
@@ -208,7 +208,7 @@ The `IO` type implements the following algebras:
208208
### Example
209209

210210
```js
211-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
211+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
212212

213213
const containerA = Task(_ => readFile(`${Deno.cwd()}/dump/hoge`))
214214
.map(text => text.split("\n"));
@@ -260,7 +260,7 @@ Please check-out [Functional IO](https://github.com/sebastienfilion/functional-d
260260
The Type factory can be used to build complex data structure.
261261

262262
```js
263-
import { factorizeType } from "https://deno.land/x/functional@v1.3.0/library/factories.js";
263+
import { factorizeType } from "https://deno.land/x/functional@v1.3.2/library/factories.js";
264264

265265
const Coordinates = factorizeType("Coordinates", [ "x", "y" ]);
266266
const vector = Coordinates(150, 200);
@@ -312,7 +312,7 @@ vector.toString();
312312
## Sum Type factory
313313

314314
```js
315-
import { factorizeSumType } from "https://deno.land/x/functional@v1.3.0/library/factories.js";
315+
import { factorizeSumType } from "https://deno.land/x/functional@v1.3.2/library/factories.js";
316316

317317
const Shape = factorizeSumType(
318318
"Shape",
@@ -436,14 +436,30 @@ const vector = Coordinates(150, 200);
436436
### `encodeText`
437437
`String → Uint8Array`
438438

439+
### `alt`
440+
`Alt a → Alt b → Alt a|b`
441+
442+
This function takes a container of any type and, an Alternative functor. Then it returns either the container or the
443+
alternative functor.
444+
The function is in support of the [Alt algebra](https://github.com/fantasyland/fantasy-land#alt).
445+
446+
```js
447+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
448+
import { alt } from "https://deno.land/x/functional@v1.3.2/library/utilities.js";
449+
450+
const container = alt(Either.Right(42), Either.Left("Not the meaning of life"));
451+
452+
assertEquals(container.extract(), 42);
453+
```
454+
439455
### `chainLift`
440456
`(a → b → c) → Chainable a → Functor b → Chainable c`
441457

442458
This function is similar to [`lift`](https://ramdajs.com/docs/#lift) but is chainable.
443459

444460
```js
445-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
446-
import { chainLift } from "https://deno.land/x/functional@v1.3.0/library/utilities.js";
461+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
462+
import { chainLift } from "https://deno.land/x/functional@v1.3.2/library/utilities.js";
447463

448464
const hogeFuga = useWith(
449465
chainLift(curry((x, y) => Task.of(x * y))),
@@ -467,8 +483,8 @@ This function is a combinator for the [`chainRec` algebra](https://github.com/fa
467483
It takes a ternary function, an initial value and, a chainable recursive functor.
468484

469485
```js
470-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
471-
import { chainRec } from "https://deno.land/x/functional@v1.3.0/library/utilities.js";
486+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
487+
import { chainRec } from "https://deno.land/x/functional@v1.3.2/library/utilities.js";
472488

473489
const multiplyAll = curry((x, n) => chainRec(
474490
(Loop, Done, cursor) =>
@@ -490,8 +506,8 @@ This function takes a type constructor and, a list of Applicative functor and ev
490506
functor of a list of value.
491507

492508
```js
493-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
494-
import { evert } from "https://deno.land/x/functional@v1.3.0/library/utilities.js";
509+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
510+
import { evert } from "https://deno.land/x/functional@v1.3.2/library/utilities.js";
495511

496512
const container = await evert(Task, [ Task.of(42), Task.of(32), Task.of(24) ]).run();
497513

@@ -511,8 +527,8 @@ This function is a composable `console.debug`. It takes a message, a value and,
511527
This function takes n Chainable functor and chain them automatically.
512528

513529
```js
514-
import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
515-
import { runSequentially } from "https://deno.land/x/functional@v1.3.0/library/utilities.js";
530+
import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
531+
import { runSequentially } from "https://deno.land/x/functional@v1.3.2/library/utilities.js";
516532

517533
const fuga = converge(
518534
runSequentially,
@@ -553,14 +569,14 @@ import {
553569
Task,
554570
factorizeType,
555571
factorySumType
556-
} from "https://deno.land/x/functional@v1.3.0/mod.ts";
572+
} from "https://deno.land/x/functional@v1.3.2/mod.ts";
557573
```
558574

559575
Or, you can import individual sub-module with the appropriate TypeScript hint in Deno.
560576

561577
```ts
562-
// @deno-types="https://deno.land/x/functional@v1.3.0/library/Either.d.ts"
563-
import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
578+
// @deno-types="https://deno.land/x/functional@v1.3.2/library/Either.d.ts"
579+
import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
564580
```
565581

566582
---

library/Either.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { $$value } from "./Symbols.js";
1616
* ### Example
1717
*
1818
* ```js
19-
* import Either from "https://deno.land/x/functional@v1.3.0/library/Either.js";
19+
* import Either from "https://deno.land/x/functional@v1.3.2/library/Either.js";
2020
*
2121
* const containerA = Either.Right(42).map(x => x + 2);
2222
* const containerB = Either.Left(new Error("The value is not 42.")).map(x => x + 2);

library/IO.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { factorizeType } from "./factories.js";
1313
* ### Example
1414
*
1515
* ```js
16-
* import IO from "https://deno.land/x/functional@v1.3.0/library/IO.js";
16+
* import IO from "https://deno.land/x/functional@v1.3.2/library/IO.js";
1717
*
1818
* const container = IO(_ => readFile(`${Deno.cwd()}/dump/hoge`))
1919
* .map(promise => promise.then(text => text.split("\n")));

library/Maybe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { $$value } from "./Symbols.js";
1515
* ### Example
1616
*
1717
* ```js
18-
* import Maybe from "https://deno.land/x/functional@v1.3.0/library/Maybe.js";
18+
* import Maybe from "https://deno.land/x/functional@v1.3.2/library/Maybe.js";
1919
*
2020
* const containerA = Maybe.Just(42).map(x => x + 2);
2121
* const containerB = Maybe.Nothing.map(x => x + 2);

library/Pair.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { factorizeType } from "./factories.js";
1414
* ### Example
1515
*
1616
* ```js
17-
* import Pair from "https://deno.land/x/functional@v1.3.0/library/Pair.js";
17+
* import Pair from "https://deno.land/x/functional@v1.3.2/library/Pair.js";
1818
*
1919
* const pair = Pair(42, 42)
2020
* .bimap(

library/Task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const concat = x => y => x.concat(y);
2121
* ### Example
2222
*
2323
* ```js
24-
* import Task from "https://deno.land/x/functional@v1.3.0/library/Task.js";
24+
* import Task from "https://deno.land/x/functional@v1.3.2/library/Task.js";
2525
*
2626
* const containerA = Task(_ => readFile(`${Deno.cwd()}/dump/hoge`))
2727
* .map(text => text.split("\n"));

library/factories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { $$inspect, $$returnType, $$tag, $$tagList, $$type, $$valueList } from "
2323
* The Type factory can be used to build complex data structure.
2424
*
2525
* ```js
26-
* import { factorizeType } from "https://deno.land/x/functional@v1.3.0/library/factories.js";
26+
* import { factorizeType } from "https://deno.land/x/functional@v1.3.2/library/factories.js";
2727
*
2828
* const Coordinates = factorizeType("Coordinates", [ "x", "y" ]);
2929
* const vector = Coordinates(150, 200);
@@ -75,7 +75,7 @@ import { $$inspect, $$returnType, $$tag, $$tagList, $$type, $$valueList } from "
7575
* ## Sum Type factory
7676
*
7777
* ```js
78-
* import { factorizeSumType } from "https://deno.land/x/functional@v1.3.0/library/factories.js";
78+
* import { factorizeSumType } from "https://deno.land/x/functional@v1.3.2/library/factories.js";
7979
*
8080
* const Shape = factorizeSumType(
8181
* "Shape",

0 commit comments

Comments
 (0)