Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 1, 2024. It is now read-only.
/funfix.jsPublic archive

Functional Programming Library for JavaScript, TypeScript and Flow ✨⚡️

License

NotificationsYou must be signed in to change notification settings

funfix/funfix.js

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.

Usage

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 funfix

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

Modules: UMD and ES 2015

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.

Sub-projects

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:

funfix-core

npm

Exposes primitive interfaces and data types that need to beuniversally 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 andhash code generation:

IEqualsan interface for defining universal equality and hash code
is andequalsfor usingIEquals in tests, or otherwise falls back to JavaScript's equality (== orvalueOf())
hashCodefor 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()
isValueObjectfor 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:

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), seeMixins for an explanation
idis the "identity" function

funfix-exec

npm

Contains low level / side-effectful utilities and data types forbuilding 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'sPromise
Schedulerthe 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 andCancelablefor expressing actions that can be triggered to cancel processes / dispose of resources
IBoolCancelable andBoolCancelablefor cancelable references that can be queried for theirisCanceled status
IAssignCancelable andAssignCancelablefor 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 likeMultiAssignCancelable except that it can be assigned only once, triggering an error on the second attempt
SerialCancelablebeing like aMultiAssignCancelable that cancels its previous underlying reference on updates

And also types for expressing durations:

TimeUnitinspired by Java's own enumeration, representing time
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 advancedIO 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 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.
IOlawful, 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

TypeScript or Flow?

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.

Contributing

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.

License

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

Stars

Watchers

Forks

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp