Skip to content

Commit e6401b4

Browse files
Implement new combinator, add documentation and, rename insideOut to evert
1 parent 979dbcb commit e6401b4

18 files changed

+2219
-11005
lines changed

.github/document.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export FL_TITLE="Functional"
2+
export FL_DESCRIPTION="Common Functional Programming Algebraic data types for JavaScript that is compatible with most modern browsers and Deno."
3+
export FL_VERSION="v1.3.0"
4+
5+
deno run --allow-all --unstable ../@functional:generate-documentation/cli.js document "$FL_TITLE" "$FL_DESCRIPTION" $FL_VERSION ./.github/readme-fragment-usage.md ./library/*.js ./.github/readme-fragment-typescript.md ./.github/readme-fragment-license.md

.github/fl-logo.svg

Lines changed: 34 additions & 0 deletions
Loading

.github/readme-fragment-license.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## License
2+
3+
Copyright © 2020 - Sebastien Filion
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

.github/readme-fragment-typescript.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## TypeScript
2+
3+
You can import any types or the factories through `mod.ts`.
4+
5+
```ts
6+
import {
7+
Either,
8+
IO,
9+
Maybe,
10+
Pair,
11+
Task,
12+
factorizeType,
13+
factorySumType
14+
} from "https://deno.land/x/[email protected]/mod.ts";
15+
```
16+
17+
Or, you can import individual sub-module with the appropriate TypeScript hint in Deno.
18+
19+
```ts
20+
// @deno-types="https://deno.land/x/[email protected]/library/Either.d.ts"
21+
import Either from "https://deno.land/x/[email protected]/library/Either.js";
22+
```
23+

.github/readme-fragment-usage.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Usage
2+
3+
This example uses the [Ramda library](https://ramdajs.com) - for simplification - but you should be able to use any library that implements
4+
the [Fantasy-land specifications](https://github.com/fantasyland/fantasy-land).
5+
6+
```js
7+
import { compose, converge, curry, map, prop } from "https://deno.land/x/[email protected]/mod.ts";
8+
import Either from "https://deno.land/x/[email protected]/library/Either.js";
9+
import Task from "https://deno.land/x/[email protected]/library/Task.js";
10+
11+
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
12+
13+
const sayHello = compose(
14+
map(
15+
converge(
16+
curry((username, email) => `Hello ${username} (${email})!`),
17+
[
18+
prop("username"),
19+
prop("email")
20+
]
21+
)
22+
),
23+
fetchUser
24+
);
25+
26+
// Calling `sayHello` results in an instance of `Task` keeping the function pure.
27+
assert(Task.is(sayHello(userID)));
28+
29+
// Finally, calling `Task#run` will call `fetch` and return a promise
30+
sayHello(userID).run()
31+
.then(container => {
32+
// The returned value should be an instance of `Either.Right` or `Either.Left`
33+
assert(Either.Right.is(container));
34+
// Forcing to coerce the container to string will show that the final value is our message.
35+
assert(container.toString(), `Either.Right("Hello johndoe ([email protected])!")`);
36+
});
37+
38+
// await sayHello(userID).run() === Either.Right(String)
39+
```
40+
41+
### Using the bundle
42+
43+
As a convenience, when using Functional in the browser, you can use the **unminified** bundled copy.
44+
45+
```js
46+
import { compose, converge, lift, map, prop } from "https://deno.land/x/[email protected]/mod.ts";
47+
import { Either, Task } from "https://deno.land/x/[email protected]/functional.js";
48+
49+
const fetchUser = userID => Task.wrap(_ => fetch(`${URL}/users/${userID}`).then(response => response.json()));
50+
51+
const sayHello = compose(
52+
map(
53+
converge(
54+
curry((username, email) => `Hello ${username} (${email})!`),
55+
[
56+
prop("username"),
57+
prop("email")
58+
]
59+
)
60+
),
61+
fetchUser
62+
);
63+
```

0 commit comments

Comments
 (0)