From 57d94e9cd3bd299c9893cfb1282c9d708f136b6e Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 23 Jul 2019 00:22:49 +0700 Subject: [PATCH 1/2] (#1137) Simplified responsibility and implementation of FirstOf --- src/main/java/org/cactoos/scalar/FirstOf.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/cactoos/scalar/FirstOf.java b/src/main/java/org/cactoos/scalar/FirstOf.java index ab5f0654a2..732fabc4ae 100644 --- a/src/main/java/org/cactoos/scalar/FirstOf.java +++ b/src/main/java/org/cactoos/scalar/FirstOf.java @@ -70,19 +70,10 @@ public FirstOf(final Func cond, final Iterable src, @Override public T value() throws Exception { - return new ScalarWithFallback<>( - () -> new HeadOf<>( - 1, + return new ItemAt<>( + 0, + this.fallback.value(), new Filtered<>(this.condition, this.source) - ).iterator().next(), - new IterableOf>( - new FallbackFrom<>( - new IterableOf>( - NoSuchElementException.class - ), - t1 -> this.fallback.value() - ) - ) ).value(); } } From 8541946151c00fe862d0851761c7b1a6f8dd1edd Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 23 Jul 2019 00:37:27 +0700 Subject: [PATCH 2/2] (#1137) improved formatting --- src/main/java/org/cactoos/scalar/FirstOf.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/cactoos/scalar/FirstOf.java b/src/main/java/org/cactoos/scalar/FirstOf.java index 732fabc4ae..447ea829da 100644 --- a/src/main/java/org/cactoos/scalar/FirstOf.java +++ b/src/main/java/org/cactoos/scalar/FirstOf.java @@ -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. @@ -71,9 +68,9 @@ public FirstOf(final Func cond, final Iterable src, @Override public T value() throws Exception { return new ItemAt<>( - 0, - this.fallback.value(), - new Filtered<>(this.condition, this.source) + 0, + this.fallback.value(), + new Filtered<>(this.condition, this.source) ).value(); } }