Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@jbgi
jbgi / Term.java
Last active November 6, 2024 12:48
Generalized Algebraic Data Types (GADT) in Java
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);
@yuri
yuri / gist:62988af42efc4b920dd3
Last active August 29, 2015 14:09
Promise-Aware Compose
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.
@ptaoussanis
ptaoussanis / transducers.clj
Last active December 8, 2024 03:24
Quick recap/commentary: Clojure transducers
(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).
@wvl
wvl / ramda.js
Last active August 29, 2015 14:03
Sample of ramda as built by bldr
(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(", ");
@staltz
staltz / introrx.md
Last active April 21, 2025 04:15
The introduction to Reactive Programming you've been missing
@LeCoupa
LeCoupa / nodejs-cheatsheet.js
Last active February 27, 2025 20:09
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
/* *******************************************************************************************
* 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); }));
@DrBoolean
DrBoolean / traversable foldable.js
Last active February 9, 2017 12:24
Traversable/Foldable of/empty issue
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) {