(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import static java.lang.System.*; | |
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
// Implementation of a pseudo-GADT in Java, translating the examples from | |
// http://www.cs.ox.ac.uk/ralf.hinze/publications/With.pdf | |
// The technique presented below is, in fact, just an encoding of a normal Algebraic Data Type | |
// using a variation of the visitor pattern + the application of the Yoneda lemma to make it | |
// isomorphic to the targeted 'GADT'. |
require ('./globals')(global); // Mixed in Ramda to global here | |
var Task = require ('data.future'), | |
M = require ('control.monads'), | |
State = require ('fantasy-states'), | |
Reader = require ('fantasy-readers'), | |
Tuple2 = require ('fantasy-tuples').Tuple2, | |
Maybe = require ('data.maybe'), | |
ST = State.StateT (Task), | |
App = Reader.ReaderT (ST); |
function pcompose() { | |
var step1; | |
var step2; | |
var tailArgs; | |
// TODO: Handle the case where only one argument is passed. | |
if (arguments.length === 2) { | |
step1 = arguments[1]; | |
step2 = arguments[0]; | |
return function(items) { | |
var value = step1(items); |
(**** ML Programs from Chapter 9 of | |
ML for the Working Programmer, 2nd edition | |
by Lawrence C. Paulson, Computer Laboratory, University of Cambridge. | |
(Cambridge University Press, 1996) | |
Copyright (C) 1996 by Cambridge University Press. | |
Permission to copy without fee is granted provided that this copyright | |
notice and the DISCLAIMER OF WARRANTY are included in any copy. |
(comment ; Fun with transducers, v2 | |
;; Still haven't found a brief + approachable overview of Clojure 1.7's new | |
;; transducers in the particular way I would have preferred myself - so here goes: | |
;;;; Definitions | |
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as: | |
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation | |
;; (The `[]` arity is actually optional; it's only used when calling | |
;; `reduce` w/o an init-accumulator). |
(function(root,factory) { if (typeof define === "function" && define.amd) { define([], factory); } else { root.ramda = factory(); }})(this, function() { | |
// src/mkArgStr.js | |
var ramda = {}; | |
var mkArgStr = ramda.mkArgStr = function(n) { | |
var arr = [], idx = -1; | |
while(++idx < n) { | |
arr[idx] = "arg" + idx; | |
} | |
return arr.join(", "); |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
/* ******************************************************************************************* | |
* THE UPDATED VERSION IS AVAILABLE AT | |
* https://github.com/LeCoupa/awesome-cheatsheets | |
* ******************************************************************************************* */ | |
// 0. Synopsis. | |
// http://nodejs.org/api/synopsis.html |
var Option = require('fantasy-options') | |
var Some = Option.Some; | |
var None = Option.None; | |
var Compose = function(x){ | |
this.val = x; | |
} | |
Compose.prototype.map = function(f){ | |
return new Compose(this.val.map(function(u){return u.map(f); })); |
Nothing.prototype.traverse = function(f) { | |
return ?.of(Nothing()); //how to get pure if we can't call f? | |
} | |
Just.prototype.traverse = function(f) { | |
return f(this.val).map(Just); | |
} | |
Nothing.prototype.foldl = function(f) { | |
return ?.empty() // same prob as traverse - need to run f() to get correct empty | |
}; | |
Just.prototype.foldl = function(f, acc) { |