Skip to content

Commit

Permalink
Fixed type infer on maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Paulo Amorim committed Feb 28, 2016
1 parent 1cebc39 commit e3b3e9a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion maybe/src/main/java/com/jmonad/maybe/IMaybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public interface IMaybe<A> {
boolean isJust();
boolean isNothing();
<B> B maybe(B def, Function<B, A> fn);
}
}
12 changes: 6 additions & 6 deletions maybe/src/main/java/com/jmonad/maybe/Maybe.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.jmonad.maybe;

public final class Maybe {
public static <T> IMaybe maybe(T value) {
if (value instanceof IMaybe) {
return (IMaybe) value;
}
public class Maybe {
public static <T> IMaybe<T> maybe(IMaybe<T> value) {
return value;
}

return value == null ? new Nothing() : new Just<T>(value);
public static <T> IMaybe<T> maybe(T value) {
return value == null ? new Nothing<T>() : new Just<T>(value);
}
}
1 change: 1 addition & 0 deletions maybe/src/test/java/com/jmonad/maybe/MaybeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class MaybeTest {
@Test public void testSample() {
assert maybe("sample").fromMaybe("").equals("sample");
}

}

0 comments on commit e3b3e9a

Please sign in to comment.