JSPM

  • Created
  • Published
  • Downloads 203
  • Score
    100M100P100Q85564F
  • License Apache-2.0

Functional programming library for Javascript

Package Exports

  • funfix

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (funfix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

"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
  • 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

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.

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.