diff --git a/src/main/java/org/cactoos/BiProc.java b/src/main/java/org/cactoos/BiProc.java index fceb567d77..8ffeafc3d4 100644 --- a/src/main/java/org/cactoos/BiProc.java +++ b/src/main/java/org/cactoos/BiProc.java @@ -39,6 +39,10 @@ * @param Type of input * @param Type of input * @since 0.20 + * @todo #1445:30min Introduce BiProcOf on the model of ProcOf, FuncOf, etc + * with constructors taking Func, BiFunc, Proc and BiProc as primary. + * Add tests similar to those of ProcOfTest, FuncOfTest, etc to fully cover + * the implementation. Use it where needed, for example in AndWithIndexTest. */ public interface BiProc { diff --git a/src/main/java/org/cactoos/proc/ForEach.java b/src/main/java/org/cactoos/proc/ForEach.java index 67d2fa07f4..0d7a5db3e1 100644 --- a/src/main/java/org/cactoos/proc/ForEach.java +++ b/src/main/java/org/cactoos/proc/ForEach.java @@ -23,7 +23,6 @@ */ package org.cactoos.proc; -import org.cactoos.Func; import org.cactoos.Proc; import org.cactoos.func.FuncOf; import org.cactoos.scalar.And; @@ -47,7 +46,7 @@ *

* There is no thread-safety guarantee. * - * @param The type to itetare over + * @param The type to iterate over * @since 1.0 */ public final class ForEach implements Proc> { @@ -55,7 +54,7 @@ public final class ForEach implements Proc> { /** * The proc. */ - private final Func func; + private final Proc proc; /** * Ctor. @@ -63,15 +62,13 @@ public final class ForEach implements Proc> { * @param proc The proc to execute */ public ForEach(final Proc proc) { - this.func = new FuncOf<>( - proc, true - ); + this.proc = proc; } @Override public void exec(final Iterable input) throws Exception { new And( - this.func, input + new FuncOf<>(this.proc, true), input ).value(); } diff --git a/src/main/java/org/cactoos/proc/ForEachInThreads.java b/src/main/java/org/cactoos/proc/ForEachInThreads.java index 37dd70b1bc..8698463318 100644 --- a/src/main/java/org/cactoos/proc/ForEachInThreads.java +++ b/src/main/java/org/cactoos/proc/ForEachInThreads.java @@ -23,7 +23,6 @@ */ package org.cactoos.proc; -import org.cactoos.Func; import org.cactoos.Proc; import org.cactoos.func.FuncOf; import org.cactoos.scalar.AndInThreads; @@ -49,7 +48,7 @@ *

* There is no thread-safety guarantee. * - * @param The type to itetare over + * @param The type to iterate over * @since 1.0 */ public final class ForEachInThreads implements Proc> { @@ -57,7 +56,7 @@ public final class ForEachInThreads implements Proc> { /** * The proc. */ - private final Func func; + private final Proc proc; /** * Ctor. @@ -65,15 +64,13 @@ public final class ForEachInThreads implements Proc> { * @param proc The proc to execute */ public ForEachInThreads(final Proc proc) { - this.func = new FuncOf<>( - proc, true - ); + this.proc = proc; } @Override public void exec(final Iterable input) throws Exception { new AndInThreads( - this.func, input + new FuncOf<>(this.proc, true), input ).value(); } diff --git a/src/main/java/org/cactoos/proc/ForEachWithIndex.java b/src/main/java/org/cactoos/proc/ForEachWithIndex.java index 725bdc7854..025a13af71 100644 --- a/src/main/java/org/cactoos/proc/ForEachWithIndex.java +++ b/src/main/java/org/cactoos/proc/ForEachWithIndex.java @@ -23,10 +23,8 @@ */ package org.cactoos.proc; -import org.cactoos.BiFunc; import org.cactoos.BiProc; import org.cactoos.Proc; -import org.cactoos.func.BiFuncOf; import org.cactoos.scalar.AndWithIndex; /** @@ -57,7 +55,7 @@ public final class ForEachWithIndex implements Proc> { /** * The proc. */ - private final BiFunc func; + private final BiProc proc; /** * Ctor. @@ -65,15 +63,13 @@ public final class ForEachWithIndex implements Proc> { * @param proc The proc to execute */ public ForEachWithIndex(final BiProc proc) { - this.func = new BiFuncOf<>( - proc, true - ); + this.proc = proc; } @Override public void exec(final Iterable input) throws Exception { new AndWithIndex( - this.func, input + this.proc, input ).value(); } } diff --git a/src/main/java/org/cactoos/proc/ProcOf.java b/src/main/java/org/cactoos/proc/ProcOf.java index 8fe9fdca5d..b65248362f 100644 --- a/src/main/java/org/cactoos/proc/ProcOf.java +++ b/src/main/java/org/cactoos/proc/ProcOf.java @@ -46,7 +46,11 @@ public final class ProcOf implements Proc { * @param fnc The proc */ public ProcOf(final Func fnc) { - this((Proc) fnc::apply); + this( + input -> { + fnc.apply(input); + } + ); } /** diff --git a/src/main/java/org/cactoos/scalar/And.java b/src/main/java/org/cactoos/scalar/And.java index 8755f8aff4..ba2d370f32 100644 --- a/src/main/java/org/cactoos/scalar/And.java +++ b/src/main/java/org/cactoos/scalar/And.java @@ -105,10 +105,21 @@ public And(final Func func, final Iterable src) { */ @SafeVarargs public And(final X subject, final Func... conditions) { + this(subject, new IterableOf<>(conditions)); + } + + /** + * Ctor. + * @param subject The subject + * @param conditions Funcs to map + * @param Type of items in the iterable + * @since 0.49 + */ + public And(final X subject, final Iterable> conditions) { this( new Mapped<>( item -> (Scalar) () -> item.apply(subject), - new IterableOf<>(conditions) + conditions ) ); } diff --git a/src/test/java/org/cactoos/io/TempFolderTest.java b/src/test/java/org/cactoos/io/TempFolderTest.java index c3be895f47..2aa8b43a9a 100644 --- a/src/test/java/org/cactoos/io/TempFolderTest.java +++ b/src/test/java/org/cactoos/io/TempFolderTest.java @@ -87,7 +87,6 @@ void deletesNonEmptyDirectory() throws Exception { filename, "" ).value(); - return true; } ) ).exec( @@ -95,7 +94,6 @@ void deletesNonEmptyDirectory() throws Exception { "file1.txt", "file2.txt", "file3.txt" ) ); - return true; } ) ).exec( @@ -129,7 +127,6 @@ void createDirectoryWithDirectoriesAndFiles() throws Exception { filename, "" ).value(); - return true; } ) ).exec( @@ -137,7 +134,6 @@ void createDirectoryWithDirectoriesAndFiles() throws Exception { "1.txt", "2.txt", "3.txt" ) ); - return true; } ) ).exec(