[not actively maintained!] A standard library for functional programming in JavaScript
Install it through npm:
$ npm install [email protected]
A special thanks to @cdoublev :>
Install it through npm.
$ npm install [email protected]
Fixes Result.filter
discarding the error value (Issue #209)
Previous version was missing the README file in the package (Issue #208)
Install it through npm or download the attached tarball.
$ npm install [email protected]
A special thank you to @Josh-Miller, @JesterXL, @andys8, and @pernas.
chain
function for Validation allows sequencing successes in a simpler way (PR #194)Alt
algebraic structure is now implemented for Maybe (PR #171 by @Josh-Miller)any
special value, and better error reporting (PR #142 by @JesterXL)Install it through npm or download the attached zip.
$ npm install [email protected]
A special thank you to @diasbruno, @gvillalta99, @MichaelQQ, @stabbylambda, @floriansimon1, and @scotttrinh.
nullableToResult
can now take a fallback value (PR #166 by @diasbruno).toString
methods can now handle objects without a .toString
method (though not yet circular objects). (PR #169)Future.recover
to Future.orElse
. Future.recover
was deprecated. (PR #146)Install it through npm or download the attached zip:
$ npm install --save [email protected]
Thanks to the contributions of @rpearce, @boris-marinov, @justin-calleja, @sotojuan, @degroote22, @RossJHagan, @syaiful6, @diasbruno, @baranovxyz, @floriansimon1, @jreut, and @framp in this and previous releases of the 2.0 branch.
nullable → maybe
conversion
(9706ab7);.fold()
method to the Maybe
structure. This works similarly to Result and Validation's .fold()
method, except the function for the Nothing
case takes no arguments
(6f59f61);collect
function (data/validation/collect
), which makes aggregating errors from failures directly a bit simpler
(#71, a677e96);validation → either
conversion
(450cb70);core/fantasy-land
module
(d761107);core/fantasy-land
module
(d5b0c74);.get()
methods are deprecated in favour of the new .unsafeGet()
methods. There was no behavioural change, just a naming one. See #42.
(278d5a7, 19910b4);(8e1b27e)
Modules that were previously named core.js
now reflect the name of the functionality they implement. This affects you if you've been importing the core.js
modules directly, rather than their folder. The following modules are affected by this change:
core/adt/core.js
→ core/adt/data.js
(exports the data
function);data/either/core.js
→ data/either/either.js
(exports the either
ADT);data/maybe/core.js
→ data/maybe/maybe.js
(exports the maybe
ADT);data/validation/core.js
→ data/validation/validation.js
(exports the validation
ADT).(7a1ef33)
Removes the data/either/fromNullable.js
module, which was moved to the data/conversions
module. This affects you if you have been importing that module directly. In that case you can import data/conversions/nullable-to-either.js
instead:
// Before
const eitherFromNullable = require('data/either/fromNullable');
// Now
const eitherFromNullable = require('data/conversions/nullable-to-either');
Note that no changes are necessary if you were importing the whole data/either
module and taking the fromNullable
method from there.
(5676d39)
Either.try
now takes a thunk, rather than being a curried-ish form of application:
// Before
Either.try((a) => a.foo())(null); // ==> Left("cannot read property 'foo' of null")
// Now
Either.try(() => null.foo()); // ==> Left("cannot read property 'foo' of null")
(PR #62)
Renames Either
→ Result
. No behaviour changes, but a bunch of terminology changes that break existing code.
Where one used to write:
const { Left, Right } = require('folktale/data/either');
One would now write:
const { Error, Ok } = require('folktale/data/result');
The data structure's name has been changed to Result. The Left
case has been changed to Error
, and the Right
case has been changed to Ok
. This affects all uses of .matchWith
as well as constructing values.
(d5e780f)
Remove the .cata()
method from core/adt
, but adds it to Maybe and Validation. This breaks any core/adt
structure that was using .cata()
instead of .matchWith()
, but makes it easier for people to migrate their code with Maybe and Validation to Folktale 2 by just replacing require('data.maybe')
with require('folktale/data/maybe')
.
(f0dd120) Several renamings to make the API consistent regarding its usage of English (see #21), so now all names in the API use US English spelling, although the documentation still uses British English spelling:
Show
derivation (core/adt/show.js
) is now called DebugRepresentation
(core/adt/derivations/debug-representation.js
);Setoid
derivation (core/adt/setoid.js
) is now called Equality
(core/adt/derivations/equality.js
). The method for providing a custom comparison function, previously .withEquality(cmp)
is now called .wthCustomComparison(cmp)
;Serialize
derivation (core/adt/serialize.js
) is now called Serialization
(core/adt/derivations/serialization.js
);core/adt/derivations.js
file, and consequently in a derivations
property of the core/adt
module, rather than directly there;partialise
function (core/lambda/partialise.js
) is now called partialize
(core/lambda/partialize.js
).Install it through npm or download the attached zip:
$ npm install --save [email protected]
.mapRejected()
was added as a counterpart of .map()
for failed Tasks
(35fbd0d).orElse()
was added as a convenient way of recovering from failed Tasks
(35fbd0d)waitAny
and waitAll
have been added as convenience over .or
and .and
methods in Task
(ea4d1c0)fromJSON
in the presence of getters, where it'd fail when trying to set values in the reified structure
(f4026e0)undefined
as null
so all keys are kept in the serialised structure
(ffee127)(da6c2e3)
nullable → validation
now takes a fallback value, so Failures are kept as semigroups. By default, if you don't pass anything, the fallback value will be undefined
, so this only breaks things if you were relying on nullableToValidation(null)
giving you Failure(null)
. To fix it, simply pass an additional parameter:
// Before
nullableToValidation(null);
Validation.fromNullable(null);
// Now
nullableToValidation(null, null);
Validation.fromNullable(null, null);
That said, you should keep your Failures as proper semigroups, so things like .apply
and .concat
will work correctly.
Install it through npm or download the attached zip:
$ npm install --save [email protected]
Thanks to the contributions of @rpearce, @boris-marinov, @justin-calleja, @sotojuan, @degroote22, @RossJHagan, and @syaiful6 in this and previous releases of the 2.0 branch. A final release will happen as soon as some browser problems are fixed :)
nodebackToTask
(and Task.fromNodeback
) allows converting callback-based functions in Node-style to Tasks automatically
(PR #116 by @rpearce)futureToPromise
and promiseToFuture
allow converting between promises and futures. The conversion isn't strictly loss-less due to the difference in semantics
(PR #119, details in #98)promisedToTask
(and Task.fromPromised
) allows converting functions that return promises to functions that return tasks
(PR #120, details in #97)(f43441b)
Future#mapRejection
has been renamed to Future#mapRejected
for consistency. To fix just replace any
calls of mapRejection
on Futures to mapRejected
:
// Before
Future.rejected(1).mapRejection(x => x + 1);
// Now
Future.rejected(1).mapRejected(x => x + 1);
Maybe
now implements Semigroup and Monoid (PR #125 by @diasbruno).Result
now implements Semigroup.folktale/data/future
is now folktale/concurrency/future
.
folktale/data/task
is now folktale/concurrency/task
.
folktale/data/conversions
is now folktale/conversions
.
folktale/core/fantasy-land
is now folktale/fantasy-land
.
folktale/data/maybe
is now folktale/maybe
.
folktale/data/result
is now folktale/result
.
folktale/data/validation
is now folktale/validation
.
The folktale/core/adt
module is now folktale/adt/union
module, which specifies that it creates union types. The data
function was also renamed to union
, and the ADT
namespace was renamed to Union
— although this one was used mostly internally.
Previously:
const { data, derivations } = require('folktale/core/adt');
const List = data('List', {
Empty(){ },
Cons(value, rest) {
return { value, rest };
}
}).derive(derivations.Equality);
Now:
const { union, derivations } = require('folktale/adt/union');
const List = union('List', {
Empty(){ },
Cons(value, rest) {
return { value, rest };
}
}).derive(derivations.Equality);