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'); | |
let Continuation = tagged('x'); | |
Continuation.prototype.of = Continuation.of = x => { | |
return new Continuation((resolve) => resolve(x)); | |
} | |
Continuation.prototype.chain = function(f) { | |
return this.x(f); |
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 Cont = require('./lazy-continuation'); | |
// pointed version | |
const c = Cont.of(5) // initial value | |
.chain((x) => { | |
return Cont.of(x + 5); // synchronous computation | |
}) | |
.chain((x) => { // async computation | |
return new Cont((resolve) => { | |
setTimeout(() => resolve(x + 15), 500); |
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 eq = (test, a1, a2) => { | |
if(a1.length === a2.length && a1.every((v,i) => v === a2[i])) { | |
return; | |
} | |
throw new Error(`Test failed: ${ test }`); | |
}; | |
{ // Functor | |
const u = Array.of([1, 2, 3]); |
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
/** | |
* The Identity monad is a monad that does not embody any computational strategy. | |
* It simply applies the bound function to its input without any modification. | |
* Computationally, there is no reason to use the Identity monad instead of the much simpler | |
* act of simply applying functions to their arguments. | |
* | |
* The purpose of the Identity monad is its fundamental role in the theory of monad transformers. | |
* Any monad transformer applied to the Identity monad yields a non-transformer version of that monad. | |
* | |
* source: https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Identity.html |
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
require('../../support'); | |
var Task = require('data.task'); | |
var _ = require('ramda'); | |
// Exercise 1 | |
// ========== | |
// Use _.add(x,y) and _.map(f,x) to make a function that increments a value inside a functor | |
var ex1 = _.map(_.add(1));; |
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 arrayReduce(xf, init, array){ | |
var value = init; | |
var idx = 0; | |
var length = array.length; | |
for(; idx < length; idx++){ | |
value = xf.step(value, array[idx]); | |
if(isReduced(value)){ | |
value = deref(value); | |
break; | |
} |
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
/** | |
* This function takes a directory path and returns a flat stream | |
* with stat objects + full file path in the .path property. | |
*/ | |
var path = require('path'); | |
var h = require('highland'); | |
var readdir = h.wrapCallback(require('fs').readdir); | |
var stat = h.wrapCallback(require('fs').stat); |
- Introduction
- Functional Programming
- Community
- Utility
- gulp-debug: Debug vinyl file streams to see what files are run through your gulp pipeline
- gulp-count: count files in vinyl stream