- Notifications
You must be signed in to change notification settings - Fork25
Functional Programming Library for JavaScript, TypeScript and Flow ✨⚡️
License
funfix/funfix.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Warning
This repository has been unmaintained and is now ARCHIVED. At the time of writing, there are better options out there, such asEffect, although this code may still provide educational value.
Funfix is a library of type classes and data types for Functional Programmingin JavaScript,TypeScript andFlow.
Inspired byScala,CatsandMonix.
The code is organized in sub-projects, for à la carte dependencies,but all types, classes and functions are exported byfunfix, so toimport everything:
npm install --save funfixOr you can depend on individual sub-projects, see below.
The library has been compiled usingUMD (Universal Module Definition),so it should work withCommonJSandAMD, for standalone usagein browsers or Node.js.
But it also provides amodule definition inpackage.json, thusproviding compatibility withECMAScript 2015 modules,for usage when used with a modern JS engine, or when bundling with atool chain that understands ES2015 modules,likeRolluporWebpack.
Funfix has been split in multiple sub-projects for à la cartedependency management. As mentioned above, you can depend oneverything by depending on thefunfix project.
These sub-projects are:
Exposes primitive interfaces and data types that need to beuniversally available, belonging into a standard library.
Quick Overview & Usage
npm install --save funfix-coreExposes types for expressing disjunctions:
| Either | data type for expressing results with two possible outcome types (a disjoint union) |
| Option | data type for expressing optional values |
| Try | data type for representing the result of computations that may result in either success or failure |
Standard interfaces and tools for dealing with universal equality andhash code generation:
| IEquals | an interface for defining universal equality and hash code |
| is andequals | for usingIEquals in tests, or otherwise falls back to JavaScript's equality (== orvalueOf()) |
| hashCode | for calculating hash codes (for usage in sets and maps data structures) usingIEquals, or otherwise falls back to calculating a hash from.valueOf() or from.toString() |
| isValueObject | for testing if a given object implementsIEquals |
Standard, reusable error types, that help with some common scenarios,working with error types being preferable to working with strings:
| DummyError | for tagging errors used for testing purposes |
| IllegalArgumentError | for signaling that a given argument is violating the contract of the called function or constructor |
| IllegalInheritanceError | for signaling that inheriting from a certain class is illegal |
| IllegalStateError | for signaling that an illegal code branch was executed and thus something is wrong with the code and needs investigation (e.g. a bug) |
| NoSuchElementError | thrown when the user expects an element to be returned from a function call, but no such element exists |
| NotImplementedError | thrown in case an implementation is missing |
| TimeoutError | thrown in case the execution of a procedure takes longer than expected |
| CompositeError | for gathering multiple errors in a single reference that can expose them as a list |
Misc utilities:
| applyMixins | for working with mixins (i.e. classes used as interfaces, with methods that have default implementations), seeMixins for an explanation |
| id | is the "identity" function |
Contains low level / side-effectful utilities and data types forbuilding higher level concurrency tools.
Quick Overview & Usage
npm install --save funfix-execScheduling tasks for asynchronous execution:
| Future | a lawful, fast, cancelable alternative to JavaScript'sPromise |
| Scheduler | the alternative to usingsetTimeout for asynchronous boundaries or delayed execution |
In support of futures and schedulers,ICancelabledata types are introduced for dealing with cancellation concerns:
| ICancelable andCancelable | for expressing actions that can be triggered to cancel processes / dispose of resources |
| IBoolCancelable andBoolCancelable | for cancelable references that can be queried for theirisCanceled status |
| IAssignCancelable andAssignCancelable | for cancelable references that can be assigned (behave like a box for) another reference |
| MultiAssignCancelable | being a mutable cancelable whose underlying reference can be updated multiple times |
| SingleAssignCancelable | for building forward references, much likeMultiAssignCancelable except that it can be assigned only once, triggering an error on the second attempt |
| SerialCancelable | being like aMultiAssignCancelable that cancels its previous underlying reference on updates |
And also types for expressing durations:
| TimeUnit | inspired by Java's own enumeration, representing time |
| Duration | inspired by Scala's own type, as a type safe representation for durations |
Defines monadic data types for controlling laziness, asynchrony and side effects.Exposes the most advancedIO implementation for JavaScript.
Quick Overview & Usage
npm install --save funfix-effectThe exposed data types:
| Eval | lawful, lazy, monadic data type, that can control evaluation, inspired by theEval type inTypelevel Cats and by theCoeval type inMonix, a more simpleIO-like type that can only handle immediate execution, no async boundaries, no error handling, not being meant for suspending side effects. |
| IO | lawful, lazy, monadic data type, capable of expressing and composing side effectful actions, including asynchronous, being the most potent and capable alternative to JavaScript'sPromise, inspired by Haskell'sIO and by theMonix Task |
Funfix supports bothTypeScriptandFlow type annotations out of the box.
It also makes the best use of the capabilities of each. For exampleTypeScript has bivariant generics, but Flow supports varianceannotations and Funfix makes use of them. Development happens inTypeScript, due to better tooling, but both are first class citizens.
The Funfix project welcomes contributions from anybody wishing toparticipate. All code or documentation that is provided must belicensed with the same license that Funfix is licensed with (Apache2.0).
Feel free to open an issue if you notice a bug, have an idea for afeature, or have a question about the code. Pull requests are alsogladly accepted. For more information, check out thecontributor guide.
All code in this repository is licensed under the Apache License,Version 2.0. SeeLICENCE.
About
Functional Programming Library for JavaScript, TypeScript and Flow ✨⚡️
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors7
Uh oh!
There was an error while loading.Please reload this page.
