Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys, re
from subprocess import check_output
commit_msg_filepath = sys.argv[1]
issue_key_regex = "([A-Z][A-Z]+-\d+)"
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
trait List[+A] {
def foldRight[B](z: B)(f: (A, B) => B): B = { ...
//wont compile
def append(ls: List[A]): List[A] = {
foldRight(ls)((a,b) => Cons(a, b))
}
/**
* Returns a collector that will collect the stream into an immutable map.
*
* @param keyMapper A function that given a stream element returns a key
* @param valueMapper A function that given a stream element returns a value
* @param <T> The type of element in the stream
* @param <K> The type of keys used in the map
* @param <V> the type of values contained in the map
* @return a collector that will collect the a stream into an immutable map
*/
public abstract class Json {
private Json() {
}
public abstract <T> T match(Function<Jseq, T> a,
Function<Jobj, T> b,
Function<Jnumber, T> c,
Function<Jstring, T> d,
Function<Jboolean, T> e,
public static String show(final Json json) {
return json.match(
seq -> seq.getElems().stream()
.map(j -> show(j))
.collect(Collectors.joining(",", "[", "]")),
jobject -> jobject.getMembers().entrySet().stream()
.map(kv -> "\"" + kv.getKey() + "\":" + show(kv.getValue()))
.collect(Collectors.joining(",", "{", "}")),
jnumber -> jnumber.getNum().toString(),
jstring -> "\"" + jstring.getStr() + "\"",
public abstract class Json {
private Json() {
}
public abstract <T> T match(Function<Jseq, T> a,
Function<Jobj, T> b,
Function<Jnumber, T> c,
Function<Jstring, T> d,
Function<Jboolean, T> e,
...
public static final class Jobj extends Json {
private final Map<String, Json> members;
public Jobj(final Map<String, Json> members) {
this.members = members;
}
public Map<String, Json> getMembers() {
public static <T> CompletableFuture<List<T>> sequence(final List<CompletableFuture<T>> futures) {
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]))
.thenApply(unit -> futures
.stream()
.map(CompletableFuture::join)
.collect(toList()));
}
@DeepSpawn
DeepSpawn / Try.java
Last active September 10, 2016 22:50
package io.atlassian.fugue;
import java.util.function.Function;
public abstract class Try<T> {
public interface CheckedFunction<T, R> {
R apply(T t) throws Throwable;
}