Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 18, 2021
2 parents cc5daf0 + c0c023b commit 6b71044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/cactoos/proc/ForEach.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@
* @param <X> The type to iterate over
* @since 1.0
*/
public final class ForEach<X> implements Proc<Iterable<X>> {
public final class ForEach<X> implements Proc<Iterable<? extends X>> {

/**
* The proc.
*/
private final Proc<X> proc;
private final Proc<? super X> proc;

/**
* Ctor.
*
* @param proc The proc to execute
*/
public ForEach(final Proc<X> proc) {
public ForEach(final Proc<? super X> proc) {
this.proc = proc;
}

@Override
public void exec(final Iterable<X> input) throws Exception {
public void exec(final Iterable<? extends X> input) throws Exception {
new And(
new FuncOf<>(this.proc, true), input
).value();
Expand Down
34 changes: 14 additions & 20 deletions src/test/java/org/cactoos/proc/ForEachTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,33 @@
*/
package org.cactoos.proc;

import java.util.LinkedList;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import java.util.Collection;
import org.cactoos.Proc;
import org.cactoos.list.ListOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasValues;

/**
* Test case for {@link ForEach}.
*
* @since 1.0
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
*/
public class ForEachTest {
@SuppressWarnings("unchecked")
final class ForEachTest {

@Test
void testProcIterable() throws Exception {
final List<Integer> list = new LinkedList<>();
new ForEach<Integer>(
list::add
).exec(
new IterableOf<>(
1, 1
)
);
void worksWithGenerics() throws Exception {
final Collection<Iterable<Number>> list = new ListOf<>();
final Proc<? super Iterable<Number>> proc = list::add;
new ForEach<Collection<Number>>(proc).exec(new ListOf<>(new ListOf<>(1), new ListOf<>(2)));
new Assertion<>(
"List does not contain mapped Iterable elements",
"Must contain elements",
list,
new IsEqual<>(
new ListOf<>(
1, 1
)
new HasValues<>(
new ListOf<>(1),
new ListOf<>(2)
)
).affirm();
}
Expand Down

0 comments on commit 6b71044

Please sign in to comment.