node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

funfix

Funfix

Travis Coverage Status Greenkeeper badge npm Join chat

Funfix is a library of type classes and data types for Functional Programming in JavaScript, TypeScript and Flow.

Inspired by Scala, Cats and Monix.

Usage

npm install --save funfix

Features Overview

The code is organized in ES2015 modules, but all types, classes and functions are exported by the root module.


core defines core data types and universal interfaces:

Option<A> data type for representing optional values, much like the "Maybe" monadic type from Haskell or "Option" from Scala
Either<L,R> data type for representing disjoint unions, for working with values of two possible types, inspired by the data type with the same name from Haskell and Scala
Try<A> data type for capturing exceptional results and manipulating them as values, being equivalent in spirit with Either<Throwable, A>, inspired by the data type with the same name from Scala
core/errors sub-module that defines the standard Error types
core/std sub-module that defines the IEquals interface for structural equality, along with other utilities

"exec" defines low level primitives for dealing with asynchrony and concurrency:

Future<A> a lawful and cancelable alternative to JavaScript's Promise
DynamicRef<A> binding mechanism for global variables, inspired by Scala's implicits
exec/cancelable sub-module that defines ICancelable and derived interfaces, classes and utilities for dealing with cancellation
exec/scheduler sub-module that defines Scheduler, for scheduling asynchronous execution, as an alternative to working straight with setTimeout
exec/time sub-module that defines TimeUnit and Duration for specifying timespans

"effect" defines data types for dealing with side effects:

Eval<A> data type for suspending synchronous side effects and controlling evaluation (e.g. memoization, error handling)

"types" defines type classes inspired by Haskell's standard library and by Typelevel Cats:

Eq a type class for determining equality between instances of the same type and that obeys the laws defined in EqLaws
Functor a type class exposing map and that obeys the laws defined in FunctorLaws
Apply a type class that extends Functor, exposing ap and that obeys the laws defined in ApplyLaws
Applicative a type class that extends Functor and Apply, exposing pure and that obeys the laws defined in ApplicativeLaws
ApplicativeError a type class that extends Applicative, for applicative types that can raise errors or recover from them and that obeys the laws defined in ApplicativeErrorLaws
FlatMap a type class that extends Functor and Apply, exposing flatMap and tailRecM and that obeys the laws defined in FlatMapLaws
Monad a type class that extends Applicative and FlatMap and that obeys the laws defined in MonadLaws
MonadError a type class that extends ApplicativeError and Monad, for monads that can raise or recover from errors and that obeys the laws defined in MonadErrorLaws

More is coming 😉

See API Docs.

TypeScript or Flow?

Funfix supports both TypeScript and Flow type annotations out of the box.

It also makes the best use of the capabilities of each. For example TypeScript has bivariant generics, but Flow supports variance annotations and Funfix makes use of them. Development happens in TypeScript, due to better tooling, but both are first class citizens.

Semantic versioning

semantic-release

Funfix versioning follows the sematic versioning (semver) specification, meaning that versions have the $major.$minor.$patch format, where any $major increment means that a breaking change happened. It's also configured with a fully automated release process, triggered by any commits on master.

Recommended Companions

Projects for usage in combination with Funfix:

  • Immutable.js: a library exposing immutable collections, by Facebook
  • JSVerify: property based testing

Contributing

The Funfix project welcomes contributions from anybody wishing to participate. All code or documentation that is provided must be licensed with the same license that Funfix is licensed with (Apache 2.0).

Feel free to open an issue if you notice a bug, have an idea for a feature, or have a question about the code. Pull requests are also gladly accepted. For more information, check out the contributor guide.

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENCE.