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
const { Left, Right } = require("fantasy-eithers"); | |
const daggy = require("daggy"); | |
Function.prototype.map = function(f) { | |
return x => f(this(x)); | |
}; | |
//- Where everything changes... | |
const login = user => (user.name == "Tom" ? Right(user) : Left("Boo")); |
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
const { tagged } = require("daggy"); | |
const Pair = tagged("Pair", ["_1", "_2"]); | |
//+ data Store p s = Store (p -> s) p | |
const Store = tagged("Store", ["lookup", "pointer"]); | |
Array.prototype.equals = function(that) { | |
return ( | |
this.length === that.length && |
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
const daggy = require("daggy"); | |
const { uncurryN } = require("wi-jit"); | |
Array.prototype.empty = () => []; | |
const Sum = daggy.tagged("Sum", ["value"]); | |
Sum.prototype.concat = function(that) { | |
return Sum(this.value + that.value); | |
}; |
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
const Promise = require("fantasy-promises"); | |
const daggy = require("daggy"); | |
//- Regular `compose` - old news! | |
//+ compose :: (b -> c) | |
//+ -> (a -> b) | |
//+ -> a -> c | |
const compose = f => g => x => f(g(x)); | |
//- `chain`-sequencing `compose`, fancily |
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
const daggy = require("daggy"); | |
const { Loop, Done } = daggy.taggedSum("Loop", { | |
Loop: ["b"], | |
Done: ["a"] | |
}); | |
Array.empty = () => []; | |
const Pair = 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
const Option = require("fantasy-options"); | |
const Either = require("fantasy-eithers"); | |
const Task = require("data.task"); | |
const { tagged } = require("daggy"); | |
const { Some, None } = Option; | |
const { Left, Right } = Either; | |
const Pair = tagged("Pair", ["_1", "_2"]); |
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
import { tagged } from "daggy"; | |
const First = tagged("First", ["val"]); | |
First.prototype.concat = function(that) { | |
return this; | |
}; | |
const Min = tagged("Min", ["val"]); |
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 repeat(operation, num) { | |
if (num <= 0) { | |
return; | |
} | |
operation(); | |
return function() { | |
return repeat(operation, --num); | |
}; | |
} |