Skip to content

Commit 74dc2a3

Browse files
committed
(#1445) Cleanup around Proc and co
1 parent ecb0cf4 commit 74dc2a3

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

src/main/java/org/cactoos/BiProc.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
* @param <X> Type of input
4040
* @param <Y> Type of input
4141
* @since 0.20
42+
* @todo #1445:30min Introduce BiProcOf on the model of ProcOf, FuncOf, etc
43+
* with constructors taking Func, BiFunc, Proc and BiProc as primary.
44+
* Add tests similar to those of ProcOfTest, FuncOfTest, etc to fully cover
45+
* the implementation. Use it where needed, for example in AndWithIndexTest.
4246
*/
4347
public interface BiProc<X, Y> {
4448

src/main/java/org/cactoos/proc/ForEach.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
package org.cactoos.proc;
2525

26-
import org.cactoos.Func;
2726
import org.cactoos.Proc;
2827
import org.cactoos.func.FuncOf;
2928
import org.cactoos.scalar.And;
@@ -47,31 +46,29 @@
4746
* <p>
4847
* There is no thread-safety guarantee.
4948
*
50-
* @param <X> The type to itetare over
49+
* @param <X> The type to iterate over
5150
* @since 1.0
5251
*/
5352
public final class ForEach<X> implements Proc<Iterable<X>> {
5453

5554
/**
5655
* The proc.
5756
*/
58-
private final Func<X, Boolean> func;
57+
private final Proc<X> proc;
5958

6059
/**
6160
* Ctor.
6261
*
6362
* @param proc The proc to execute
6463
*/
6564
public ForEach(final Proc<X> proc) {
66-
this.func = new FuncOf<>(
67-
proc, true
68-
);
65+
this.proc = proc;
6966
}
7067

7168
@Override
7269
public void exec(final Iterable<X> input) throws Exception {
7370
new And(
74-
this.func, input
71+
new FuncOf<>(this.proc, true), input
7572
).value();
7673
}
7774

src/main/java/org/cactoos/proc/ForEachInThreads.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
package org.cactoos.proc;
2525

26-
import org.cactoos.Func;
2726
import org.cactoos.Proc;
2827
import org.cactoos.func.FuncOf;
2928
import org.cactoos.scalar.AndInThreads;
@@ -49,31 +48,29 @@
4948
* <p>
5049
* There is no thread-safety guarantee.
5150
*
52-
* @param <X> The type to itetare over
51+
* @param <X> The type to iterate over
5352
* @since 1.0
5453
*/
5554
public final class ForEachInThreads<X> implements Proc<Iterable<X>> {
5655

5756
/**
5857
* The proc.
5958
*/
60-
private final Func<X, Boolean> func;
59+
private final Proc<X> proc;
6160

6261
/**
6362
* Ctor.
6463
*
6564
* @param proc The proc to execute
6665
*/
6766
public ForEachInThreads(final Proc<X> proc) {
68-
this.func = new FuncOf<>(
69-
proc, true
70-
);
67+
this.proc = proc;
7168
}
7269

7370
@Override
7471
public void exec(final Iterable<X> input) throws Exception {
7572
new AndInThreads(
76-
this.func, input
73+
new FuncOf<>(this.proc, true), input
7774
).value();
7875
}
7976

src/main/java/org/cactoos/proc/ForEachWithIndex.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
*/
2424
package org.cactoos.proc;
2525

26-
import org.cactoos.BiFunc;
2726
import org.cactoos.BiProc;
2827
import org.cactoos.Proc;
29-
import org.cactoos.func.BiFuncOf;
3028
import org.cactoos.scalar.AndWithIndex;
3129

3230
/**
@@ -57,23 +55,21 @@ public final class ForEachWithIndex<X> implements Proc<Iterable<X>> {
5755
/**
5856
* The proc.
5957
*/
60-
private final BiFunc<X, Integer, Boolean> func;
58+
private final BiProc<X, Integer> proc;
6159

6260
/**
6361
* Ctor.
6462
*
6563
* @param proc The proc to execute
6664
*/
6765
public ForEachWithIndex(final BiProc<X, Integer> proc) {
68-
this.func = new BiFuncOf<>(
69-
proc, true
70-
);
66+
this.proc = proc;
7167
}
7268

7369
@Override
7470
public void exec(final Iterable<X> input) throws Exception {
7571
new AndWithIndex(
76-
this.func, input
72+
this.proc, input
7773
).value();
7874
}
7975
}

src/main/java/org/cactoos/proc/ProcOf.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public final class ProcOf<X> implements Proc<X> {
4646
* @param fnc The proc
4747
*/
4848
public ProcOf(final Func<X, ?> fnc) {
49-
this((Proc<X>) fnc::apply);
49+
this(
50+
input -> {
51+
fnc.apply(input);
52+
}
53+
);
5054
}
5155

5256
/**

src/main/java/org/cactoos/scalar/And.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,21 @@ public <X> And(final Func<X, Boolean> func, final Iterable<X> src) {
105105
*/
106106
@SafeVarargs
107107
public <X> And(final X subject, final Func<X, Boolean>... conditions) {
108+
this(subject, new IterableOf<>(conditions));
109+
}
110+
111+
/**
112+
* Ctor.
113+
* @param subject The subject
114+
* @param conditions Funcs to map
115+
* @param <X> Type of items in the iterable
116+
* @since 0.49
117+
*/
118+
public <X> And(final X subject, final Iterable<Func<X, Boolean>> conditions) {
108119
this(
109120
new Mapped<>(
110121
item -> (Scalar<Boolean>) () -> item.apply(subject),
111-
new IterableOf<>(conditions)
122+
conditions
112123
)
113124
);
114125
}

src/test/java/org/cactoos/io/TempFolderTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ void deletesNonEmptyDirectory() throws Exception {
8787
filename,
8888
""
8989
).value();
90-
return true;
9190
}
9291
)
9392
).exec(
9493
new IterableOf<>(
9594
"file1.txt", "file2.txt", "file3.txt"
9695
)
9796
);
98-
return true;
9997
}
10098
)
10199
).exec(
@@ -129,15 +127,13 @@ void createDirectoryWithDirectoriesAndFiles() throws Exception {
129127
filename,
130128
""
131129
).value();
132-
return true;
133130
}
134131
)
135132
).exec(
136133
new IterableOf<>(
137134
"1.txt", "2.txt", "3.txt"
138135
)
139136
);
140-
return true;
141137
}
142138
)
143139
).exec(

0 commit comments

Comments
 (0)