Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 3, 2019
2 parents b85b3e5 + 8541946 commit fd95524
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/main/java/org/cactoos/scalar/FirstOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
*/
package org.cactoos.scalar;

import java.util.NoSuchElementException;
import org.cactoos.Func;
import org.cactoos.Scalar;
import org.cactoos.iterable.Filtered;
import org.cactoos.iterable.HeadOf;
import org.cactoos.iterable.IterableOf;

/**
* Find first element in a list that satisfies specified condition.
Expand Down Expand Up @@ -70,19 +67,10 @@ public FirstOf(final Func<T, Boolean> cond, final Iterable<T> src,

@Override
public T value() throws Exception {
return new ScalarWithFallback<>(
() -> new HeadOf<>(
1,
new Filtered<>(this.condition, this.source)
).iterator().next(),
new IterableOf<FallbackFrom<T>>(
new FallbackFrom<>(
new IterableOf<Class<? extends Throwable>>(
NoSuchElementException.class
),
t1 -> this.fallback.value()
)
)
return new ItemAt<>(
0,
this.fallback.value(),
new Filtered<>(this.condition, this.source)
).value();
}
}

0 comments on commit fd95524

Please sign in to comment.