7.0.1 • Published 6 years ago

funfix v7.0.1

Weekly downloads
1,045
License
Apache-2.0
Repository
github
Last release
6 years ago

Funfix

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

The code is organized in sub-projects, for à la carte dependencies, but all types, classes and functions are exported by funfix, so to import everything:

npm install --save funfix

Or you can depend on individual sub-projects, see below.

Modules: UMD and ES 2015

The library has been compiled using UMD (Universal Module Definition), so it should work with CommonJS and AMD, for standalone usage in browsers or Node.js.

But it also provides a module definition in package.json, thus providing compatibility with ECMAScript 2015 modules, for usage when used with a modern JS engine, or when bundling with a tool chain that understands ES2015 modules, like Rollup or Webpack.

Sub-projects

Funfix has been split in multiple sub-projects for à la carte dependency management. As mentioned above, you can depend on everything by depending on the funfix project.

These sub-projects are:

funfix-core

npm

Exposes primitive interfaces and data types that need to be universally available, belonging into a standard library.

See JSDoc documentation.

Quick Overview & Usage

npm install --save funfix-core

Exposes types for expressing disjunctions:

Eitherdata type for expressing results with two possible outcome types (a disjoint union)
Optiondata type for expressing optional values
Trydata type for representing the result of computations that may result in either success or failure

Standard interfaces and tools for dealing with universal equality and hash code generation:

IEqualsan interface for defining universal equality and hash code
is and equalsfor using IEquals in tests, or otherwise falls back to JavaScript's equality (== or valueOf())
hashCodefor calculating hash codes (for usage in sets and maps data structures) using IEquals, or otherwise falls back to calculating a hash from .valueOf() or from .toString()
isValueObjectfor testing if a given object implements IEquals

Standard, reusable error types, that help with some common scenarios, working with error types being preferable to working with strings:

DummyErrorfor tagging errors used for testing purposes
IllegalArgumentErrorfor signaling that a given argument is violating the contract of the called function or constructor
IllegalInheritanceErrorfor signaling that inheriting from a certain class is illegal
IllegalStateErrorfor signaling that an illegal code branch was executed and thus something is wrong with the code and needs investigation (e.g. a bug)
NoSuchElementErrorthrown when the user expects an element to be returned from a function call, but no such element exists
NotImplementedErrorthrown in case an implementation is missing
TimeoutErrorthrown in case the execution of a procedure takes longer than expected
CompositeErrorfor gathering multiple errors in a single reference that can expose them as a list

Misc utilities:

applyMixinsfor working with mixins (i.e. classes used as interfaces, with methods that have default implementations), see Mixins for an explanation
idis the "identity" function

funfix-exec

npm

Contains low level / side-effectful utilities and data types for building higher level concurrency tools.

See JSDoc documentation.

Quick Overview & Usage

npm install --save funfix-exec

Scheduling tasks for asynchronous execution:

Futurea lawful, fast, cancelable alternative to JavaScript's Promise
Schedulerthe alternative to using setTimeout for asynchronous boundaries or delayed execution

In support of futures and schedulers, ICancelable data types are introduced for dealing with cancellation concerns:

ICancelable and Cancelablefor expressing actions that can be triggered to cancel processes / dispose of resources
IBoolCancelable and BoolCancelablefor cancelable references that can be queried for their isCanceled status
IAssignCancelable and AssignCancelablefor cancelable references that can be assigned (behave like a box for) another reference
MultiAssignCancelablebeing a mutable cancelable whose underlying reference can be updated multiple times
SingleAssignCancelablefor building forward references, much like MultiAssignCancelable except that it can be assigned only once, triggering an error on the second attempt
SerialCancelablebeing like a MultiAssignCancelable that cancels its previous underlying reference on updates

And also types for expressing durations:

TimeUnitinspired by Java's own enumeration, representing timeelated units of measurement
Durationinspired by Scala's own type, as a type safe representation for durations

funfix-effect

npm

Defines monadic data types for controlling laziness, asynchrony and side effects. Exposes the most advanced IO implementation for JavaScript.

See JSDoc documentation.

Quick Overview & Usage

npm install --save funfix-effect

The exposed data types:

Evallawful, lazy, monadic data type, that can control evaluation, inspired by the Eval type in Typelevel Cats and by the Coeval type in Monix, a more simple IO-like type that can only handle immediate execution, no async boundaries, no error handling, not being meant for suspending side effects.
IOlawful, lazy, monadic data type, capable of expressing and composing side effectful actions, including asynchronous, being the most potent and capable alternative to JavaScript's Promise, inspired by Haskell's IO and by the Monix Task

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.

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.

7.0.1

6 years ago

7.0.0

6 years ago

7.0.0-rc.3

6 years ago

7.0.0-rc.2

6 years ago

7.0.0-rc.1

6 years ago

6.2.2

7 years ago

6.2.1

7 years ago

6.2.0

7 years ago

6.1.0

7 years ago

6.0.2

7 years ago

6.0.1

7 years ago

6.0.0

7 years ago

5.0.1

7 years ago

4.5.0

7 years ago

4.4.0

7 years ago

4.3.1

7 years ago

4.3.0

7 years ago

4.2.0

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.8.0

7 years ago

3.7.1

7 years ago

3.7.0

7 years ago

3.6.0

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.5.0

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago