Skip to content

Instantly share code, notes, and snippets.

@janickr
janickr / Transducers.java
Created October 11, 2014 21:42
Transducers in java. An exercise based on http://phuu.net/2014/08/31/csp-and-transducers.html
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
public class Transducers {
static interface Reducer<Something, Input> extends BiFunction<Something, Input, Something> {}
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import static java.util.Arrays.asList;
public class Combinators {
public static <A, B, R> BiFunction<B, A, R> flip(BiFunction<A, B, R> fn) {
@janickr
janickr / conway.sql
Last active September 10, 2020 21:49
conway's game of life in SQL (postgresql) - http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
with recursive generation1(x,y) as ( --the initial board setup
select 2, 3
union
select 3, 3
union
select 4, 3
),
game(n, x, y) as (
select 1, x, y from generation1 -- generation 1 is initial board setup
union all