This file contains 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
-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}) -> |
This file contains 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
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" |
This file contains 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
private static ArgumentMatcher<Object[]> VarArgsEq(Object... expectedValues){ | |
return new CustomVarargMatcher(expectedValues); | |
} |
This file contains 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 CustomVarargMatcher extends ArgumentMatcher<Object[]> implements VarargMatcher { | |
private String[] expectedValues; | |
CustomVarargMatcher(Object... expectedValues) { | |
this.expectedValues = expectedValues; | |
} | |
@Override | |
public boolean matches(Object varargArgument) { | |
return new EqualsBuilder() |
This file contains 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
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; |
This file contains 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
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()); | |
} |
This file contains 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
static BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b; | |
static Function<Integer, Function<Integer, Integer>> addCurried = a -> b -> add.apply(a,b); |
This file contains 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
private int add(int a, int b){ | |
return a + b; | |
} |
This file contains 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
Function<Integer,Integer> add(int a){ | |
return new Function<Integer,Integer>(){ | |
@Override | |
public Integer apply(final Integer b) { | |
return a + b; | |
} | |
}; | |
} |
This file contains 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
//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); | |
} |
NewerOlder