Skip to content

Commit

Permalink
Merge pull request #507 from danieldietrich/mapAndFlatMap
Browse files Browse the repository at this point in the history
map and flatMap
  • Loading branch information
danieldietrich committed Aug 24, 2015
2 parents 938a642 + 10894a0 commit 5285156
Show file tree
Hide file tree
Showing 39 changed files with 649 additions and 697 deletions.
73 changes: 0 additions & 73 deletions src/main/java/javaslang/FilterMonadic.java

This file was deleted.

54 changes: 0 additions & 54 deletions src/main/java/javaslang/Kind.java

This file was deleted.

19 changes: 9 additions & 10 deletions src/main/java/javaslang/Lazy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
package javaslang;

import javaslang.collection.Iterator;
import javaslang.collection.List;
import javaslang.control.None;
import javaslang.control.Option;
import javaslang.control.Some;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
Expand Down Expand Up @@ -41,8 +37,7 @@
*
* @since 1.2.1
*/
public final class Lazy<T> implements Supplier<T>, Value<T>, Serializable,
FilterMonadic<Lazy<?>, T>, Kind<Lazy<?>, T> {
public final class Lazy<T> implements Supplier<T>, Value<T>, Serializable {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -136,7 +131,7 @@ public T get() {
*/
@Override
public boolean isEmpty() {
return false;
return isEmpty;
}

/**
Expand Down Expand Up @@ -170,13 +165,17 @@ public Lazy<T> filter(Predicate<? super T> predicate) {
}

public <U> Lazy<U> flatMap(Function<? super T, ? extends Lazy<? extends U>> mapper) {
return Lazy.of(() -> mapper.apply(get()).get());
return flatMapVal(mapper);
}

@SuppressWarnings("unchecked")
@Override
public <U> Lazy<U> flatMapM(Function<? super T, ? extends Kind<? extends Lazy<?>, ? extends U>> mapper) {
return flatMap((Function<? super T, ? extends Lazy<? extends U>>) mapper);
public <U> Lazy<U> flatMapVal(Function<? super T, ? extends Value<? extends U>> mapper) {
if (isEmpty()) {
return (Lazy<U>) this;
} else {
return Lazy.of(() -> mapper.apply(get()).get());
}
}

@Override
Expand Down
Loading

0 comments on commit 5285156

Please sign in to comment.