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 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
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
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
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
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
def log_arguments(function_to_wrap): | |
def new_wrapped_function(*args, **kwargs): | |
name = function_to_wrap.func_name | |
print("Calling {} with args {} and kwargs {}".format( | |
name, args, kwargs)) | |
return function_to_wrap(*args, **kwargs) | |
return new_wrapped_function | |
def add(a, b): | |
return a + b |
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
#!/usr/bin/env ruby | |
# | |
# check-git-remote-version.rb | |
# | |
# DESCRIPTION: | |
# Ensure git repo is in-sync with remote | |
# This check verifies that the current version of a git repo reflects the | |
# latest version of a particular ref on a named remote repository. | |
# | |
# PLATFORMS: |
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 Example { | |
<T, R, E extends Exception> Function<T, Optional<R>> safely(Function<T, R> fun, Class<E> exc) { | |
return v -> { | |
try { | |
return Optional.ofNullable(fun.apply(v)); | |
} catch (Exception e) { | |
if (exc.isInstance(e)) { | |
return Optional.empty(); | |
} else { | |
throw e; |