All Projects → fantasyland → Static Land

fantasyland / Static Land

Licence: mit
Specification for common algebraic structures in JavaScript based on Fantasy Land

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Static Land

Purify
Functional programming library for TypeScript - https://gigobyte.github.io/purify/
Stars: ✭ 843 (+20.6%)
Mutual labels:  monad, algebraic-data-types, functor, functional-programming
Witchcraft
Monads and other dark magic for Elixir
Stars: ✭ 864 (+23.61%)
Mutual labels:  monad, algebraic-data-types, functor, algebra
Functionaljava
Functional programming in Java
Stars: ✭ 1,472 (+110.59%)
Mutual labels:  monad, algebraic-data-types, algebra, functional-programming
Lambda
Functional patterns for Java
Stars: ✭ 737 (+5.44%)
Mutual labels:  monad, algebraic-data-types, functor, functional-programming
Fp Core.rs
A library for functional programming in Rust
Stars: ✭ 772 (+10.44%)
Mutual labels:  monad, functor, functional-programming
Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (-50.5%)
Mutual labels:  monad, algebraic-data-types, functional-programming
Fp Resources
Functional programming great resources
Stars: ✭ 369 (-47.21%)
Mutual labels:  monad, algebra, functional-programming
Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+467.1%)
Mutual labels:  monad, functor, functional-programming
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+221.75%)
Mutual labels:  monad, algebraic-data-types, functional-programming
Whyhaskellmatters
In this article I try to explain why Haskell keeps being such an important language by presenting some of its most important and distinguishing features and detailing them with working code examples. The presentation aims to be self-contained and does not require any previous knowledge of the language.
Stars: ✭ 418 (-40.2%)
Mutual labels:  algebraic-data-types, functor, functional-programming
Derive4j
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.
Stars: ✭ 511 (-26.9%)
Mutual labels:  algebraic-data-types, algebra, functional-programming
Learn Fp
learn-by-doing course/tutorial for functional programming on scala
Stars: ✭ 548 (-21.6%)
Mutual labels:  monad, functor, functional-programming
Mostly Adequate Guide Chinese
函数式编程指北中文版
Stars: ✭ 2,093 (+199.43%)
Mutual labels:  monad, functor, functional-programming
Functional Examples
Examples with Functional JavaScript, following Professor Frisby's course
Stars: ✭ 179 (-74.39%)
Mutual labels:  monad, functor, functional-programming
Funcadelic.js
Functional programming and category theory for everyday JavaScript development
Stars: ✭ 183 (-73.82%)
Mutual labels:  monad, functor, functional-programming
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (-23.03%)
Mutual labels:  monad, functor, functional-programming
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (-91.7%)
Mutual labels:  monad, functor
function-composition-cheatsheet
Composition of Functions
Stars: ✭ 24 (-96.57%)
Mutual labels:  monad, functor
Mu Scala
Mu is a purely functional library for building RPC endpoint based services with support for RPC and HTTP/2
Stars: ✭ 266 (-61.95%)
Mutual labels:  algebra, functional-programming
J-Curry
A Java library that enables applying Functional Programming concepts like currying and partial application for functions, also it supports types like Either, Try, etc... using RxJava 2 interfaces, compatible with Java 7 and above
Stars: ✭ 17 (-97.57%)
Mutual labels:  monad, functor

Static Land

This is a specification for common algebraic structures in JavaScript based on Fantasy Land.

Difference from Fantasy Land

Fantasy Land uses methods to define interfaces that a type must implement in order to support a particular Algebra. For example values of a type that implements the Monoid algebra must have fantasy-land/empty and fantasy-land/concat methods on them.

Static Land takes a different approach. Instead of methods, we use static functions, that are grouped together in modules.

For example, here is an Addition module that uses numbers as values and satisfies the Monoid algebra requirements:

const Addition = {

  empty() {
    return 0
  },

  concat(a, b) {
    return a + b
  },

}

Pros

  • No name clashes. Since a module is just a collection of functions that don't share any namespace we don't have problems with name clashes.
  • We can implement many modules for one type, therefore we can have more than one instance of the same Algebra for a single type. For example, we can implement two Monoids for numbers: Addition and Multiplication.
  • We can implement modules that work with built-in types as values (Number, Boolean, Array, etc).

Cons

  • We have to pass around modules when we write generic code. In Fantasy Land most of generic code can be written using only methods, only if we need methods like of or empty we might need to pass the type representative. (This can be fixed!)

How to add compatibility with Static Land to your library

Simply expose a module that works with types that your library provides or with types defined in another library or with native types like Array.

Modules don't have to be simple JavaScript objects; they can also be constructors if desired. The only requirements are:

  • this object contains some static methods from Static Land; and
  • if it contains a method with one of the names that Static Land reserves, that method must be the Static Land method (obey laws etc).

Example 1. Static Land module for Array

const SArray = {

  of(x) {
    return [x]
  },

  map(fn, arr) {
    return arr.map(fn)
  },

  chain(fn, arr) {
    // ...
  },

}

export {SArray}

Example 2. Static Land module as a Class

class MyType {

  constructor() {
    // ...
  }

  someInstanceMethod() {
    // ...
  }

  static someNonStaticLandStaticMethod() {
    // ...
  }


  // Static Land methods

  static of(x) {
    // ...
  }

  static map(fn, value) {
    // ...
  }

}

export {MyType}

Example 3. Static Land module as ECMAScript modules

// mytype.js

// Static Land methods

export function of(x) {
  // ...
}

export function map(fn, value) {
  // ...
}

Import as

import * as MyType from "./mytype" // MyType is now a Static Land module

Compatible libraries

We have a list in the wiki. Feel free to add your library there.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].