Skip to content

Instantly share code, notes, and snippets.

View gtrefs's full-sized avatar

Gregor Trefs gtrefs

  • Mannheim, Germany
View GitHub Profile
@gtrefs
gtrefs / Chapter1.java
Last active January 18, 2022 22:17
Category Theory For Programmers Chapter 1
package eu.javaland.fpworkshop.categorytheory;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.function.Function;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
package de.gtrefs.fizzbuzz.more;
import javaslang.collection.Stream;
import javaslang.test.Arbitrary;
import javaslang.test.Property;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class FizzBuzzStream {
@gtrefs
gtrefs / Primes.java
Created March 11, 2016 19:36
Java 8 Primes
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.stream.IntStream;
import org.junit.Test;
public class Primes {
final IntPredicate isPrime = x -> IntStream.rangeClosed(2, (int) (Math.sqrt(x))).allMatch(n -> x % n != 0);
final Function<Integer, IntStream> till = max -> IntStream.iterate(1, i -> i + 1).filter(isPrime).limit(max);
@gtrefs
gtrefs / checker.py
Created September 2, 2015 11:45
GitHub user name checker
import os
import requests
import sys
def read_list_of_java_annotations(path):
if os.path.isfile(path):
with open(path, "r") as f:
return map(lambda s: s.strip(), f.readlines())
else:
return []