Ramda | Sanctuary |
---|---|
add(a, b) |
add(a, b) |
addIndex(f) |
`` |
adjust(f, i, xs) |
`` |
all(f, xs) |
`` |
allPass(fs, x) |
allPass(fs, x) |
always(x) |
K(x) |
and(a, b) |
and(a, b) |
any(f, x) |
`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FooBar = { foo :: String , bar? :: Int } | |
r :: FooBar | |
r = { foo: "foo" } | |
foo :: String | |
foo = r.foo -- "foo" | |
bar :: Maybe Int | |
bar = r.bar -- Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Data.Array (snoc) | |
import Data.Foldable (fold) | |
import Data.Tuple.Nested (type (/\), (/\)) | |
import TryPureScript (h1, render, text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from https://github.com/russellmcc/fantasydo/blob/master/index.js | |
// The `monad` argument has been added to avoid modifying the prototype of | |
// the yielded value to provide `pure` and `bind`. | |
// Note: | |
// This algorithm is not stack safe, and is inefficient due to the | |
// requirement that we bring the generator up to the previous state on each | |
// iteration. | |
// I suspect it's particularly bad for arrays. I may come back to this at | |
// some point to calculate just how bad it really is. | |
const Do = monad => genFn => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Calling _.foo.bar with a value returns the value at the end of that path (if it exists), `undefined` otherwise. | |
Constructing _.foo.bar with a function returns a function that immutably updates a value if the path matches, returns the original otherwise. | |
Usage: | |
> [{foo: {bar: 1}}, {foo: {bar: 2}}, {foo: {bar: 3}}, {foo: {bur: 4}}].map(_.foo.bar) | |
[1, 2, 3, undefined] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Record.Unsafe (unsafeDelete) | |
import Effect (Effect) | |
import TryPureScript (h1, text, render) | |
r :: forall t. Record (x :: Boolean, x :: Int, x :: String, x :: t) | |
r = { x: [3] } { x = true } | |
r2 :: forall t. Record (x :: Boolean, x :: Int, x :: String, x :: t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isWrapper = Symbol('isWrapper'); | |
function _(arg, args=[], ops=[]) { | |
const myArgs = args.concat([arg]); | |
const myOps = ops.slice(0); | |
const f = ([op]) => ( | |
myOps.push(op), | |
wrap(arg2 => _(arg2, myArgs, myOps), myArgs, myOps) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fix.js | |
// _has :: String => Boolean | |
var _has = k => _[k] != null; | |
// last :: Array a => a? | |
var last = xs => xs[xs.length-1]; | |
// copyArray :: Array a => Array a | |
var copyArray = xs => xs.slice(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _(x) { | |
if (x instanceof _) return new _(x._); | |
if (!(this instanceof _)) return new _(x); | |
this._ = x; | |
} | |
_.mixfix = function mixfix(pattern, f) { | |
const [name, ...names] = pattern.split('_'); | |
let startIndex = name === '' ? 1 : 0; |
In Fantasy Land, types are specified by an object containing a catamorphic
method cata
. cata
has an arity matching the number of constructor functions
belonging to each type. Each argument to cata
is either:
- a value
- a function with an arity matching the number of arguments to the constructor
function.
- Each function argument to
cata
must return a value of the same type as
- Each function argument to
NewerOlder