22
33Common 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
2626import { 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
3030const 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
6565import { 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
6868const 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
101101const containerA = Either .Right (42 ).map (x => x + 2 );
102102const 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
131131const 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
159159const containerA = Maybe .Just (42 ).map (x => x + 2 );
160160const 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
186186const 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
213213const 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
260260The 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
265265const Coordinates = factorizeType (" Coordinates" , [ " x" , " y" ]);
266266const 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
317317const 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
442458This 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
448464const 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
467483It 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
473489const 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
490506functor 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
496512const 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,
511527This 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
517533const 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
559575Or, 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---
0 commit comments