Skip to content

Instantly share code, notes, and snippets.

-module(assignment1).
-author("gtaylor").
%% API
-export([perimeter/1, area/1, distance/2, sides/1, toRectange/2, enclose/1, bits/1, bitsRec/1]).
% triangle tuple representation
% {triangle, {Ax,Ay}, {Bx,By}, {Cx,Cy}}
sides({triangle, A, B, C}) ->
Prelude λ: 2
2
Prelude λ: 3.0
3.0
Prelude λ: 5 / 2
2.5
Prelude λ: "this is a string"
"this is a string"
Prelude λ: "this is a string" ++ " this is more text"
"this is a string this is more text"
private static ArgumentMatcher<Object[]> VarArgsEq(Object... expectedValues){
return new CustomVarargMatcher(expectedValues);
}
class CustomVarargMatcher extends ArgumentMatcher<Object[]> implements VarargMatcher {
private String[] expectedValues;
CustomVarargMatcher(Object... expectedValues) {
this.expectedValues = expectedValues;
}
@Override
public boolean matches(Object varargArgument) {
return new EqualsBuilder()
public abstract class Parent<T> {
public abstract Parent<T> goodMethod(Function<Integer, Parent<T>> f);
public abstract <TT extends T> Parent<TT> badMethod(Function<Integer, Parent<TT>> f);
private static final class Child<T> extends Parent<T> {
T value;
public static void curryDemo(){
Function<Integer,Integer> add5 = addCurried.apply(5);
IntStream.range(1,10)
//.map(i -> add(i,5))
.map(add5::apply)
.boxed()
.collect(Collectors.toList());
}
static BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
static Function<Integer, Function<Integer, Integer>> addCurried = a -> b -> add.apply(a,b);
private int add(int a, int b){
return a + b;
}
Function<Integer,Integer> add(int a){
return new Function<Integer,Integer>(){
@Override
public Integer apply(final Integer b) {
return a + b;
}
};
}
//Given
interface CheckedFunction<T, R> {
R apply(T t) throws Exception;
}
//Does not compile
public <U> Try<U> flatMap(final CheckedFunction<? super T, Try<U>> f) {
return f.apply(value);
}