Skip to content

Instantly share code, notes, and snippets.

View afcastano's full-sized avatar

Andres Castano afcastano

View GitHub Profile
@tonymorris
tonymorris / PureIO.java
Last active December 18, 2017 02:30
Pure-functional terminal I/O in java
import java.util.function.Function;
import java.util.function.BiFunction;
import java.util.Scanner;
abstract class TerminalOperation<A> {
// this ensures that there are no subclasses of TerminalOperation
// outside of this class
private TerminalOperation() {
}
@ms-tg
ms-tg / jdk8_optional_monad_laws.java
Created November 11, 2013 21:14
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```
@briancavalier
briancavalier / promise-monad-proof.js
Created August 8, 2012 15:57
A proof that Promises/A is a Monad
//-------------------------------------------------------------
//
// Hypothesis:
//
// Promises/A is a Monad
//
// To be a Monad, it must provide at least:
// - A unit (aka return or mreturn) operation that creates a corresponding
// monadic value from a non-monadic value.
// - A bind operation that applies a function to a monadic value