This file contains hidden or 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
class Node | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
@children = [] | |
end | |
def children | |
@children.dup.freeze |
This file contains hidden or 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 'rest-client' | |
require 'json' | |
module Sensu | |
class Server | |
attr_reader :name, :hostname, :port | |
def initialize(name, hostname, port = 4567) | |
@name = name | |
@hostname = hostname | |
@port = port |
This file contains hidden or 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
package com.mkbernard.functional.examples; | |
import java.util.List; | |
import java.util.function.Function; | |
import com.google.common.collect.ImmutableList; | |
public abstract class Expr<A> { | |
public abstract <T> T match(Function<Value<A>, T> value, Function<Add<A>, T> add); |
This file contains hidden or 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
package com.mkbernard.functional.examples; | |
import java.util.function.Function; | |
public abstract class Coproduct<A, B> { | |
public abstract boolean isLeft(); | |
public abstract boolean isRight(); | |
public abstract Left<A, B> left(); | |
public abstract Right<A, B> right(); |
This file contains hidden or 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
import java.util.function.Function; | |
public class Const<A, B> implements Functor<B> { | |
private final A value; | |
private Const(A value) { | |
this.value = value; | |
} | |
public static <A, B> Const<A, B> of(A value) { |
This file contains hidden or 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
import static org.assertj.core.api.Assertions.assertThat; | |
import java.util.Map; | |
import java.util.Optional; | |
import java.util.Set; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
import com.google.common.collect.ImmutableMap; | |
import com.google.common.collect.ImmutableSet; |
This file contains hidden or 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
import static org.assertj.core.api.Assertions.assertThat; | |
import java.util.function.Function; | |
import org.junit.Test; | |
import io.atlassian.fugue.Either; | |
public class ChainTest { | |
static class Context<T, Status extends Enum<Status>> { |
This file contains hidden or 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
import java.util.Collection; | |
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
public interface Fold<Acc, From, To> { | |
Acc empty(); | |
Acc step(Acc acc, From x); | |
To combine(Acc acc); |
This file contains hidden or 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
import java.util.function.BiFunction; | |
import java.util.function.Supplier; | |
public interface Monoid<T> extends Semigroup<T> { | |
T empty(); | |
static <T> Monoid<T> of(Supplier<T> v, BiFunction<T, T, T> app) { | |
return new Monoid<>() { | |
@Override | |
public T empty() { |
This file contains hidden or 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
import java.util.Collection; | |
import java.util.List; | |
import java.util.function.Function; | |
public interface Fold<Acc, From, To> { | |
Monoid<Acc> ev(); | |
Acc quantify(From x); | |
To combine(Acc acc); | |
default To fold(Collection<From> xs) { |