Skip to content

Commit

Permalink
#1669 new ctor for Reduced
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 16, 2022
1 parent a3ddd80 commit ff947ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/cactoos/scalar/Reduced.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public Reduced(
this(reduce, new Mapped<>(Constant::new, values));
}

/**
* Ctor.
* @param values Values to be wrapped as scalars
* @param reduce Reducing function
* @since 0.55.0
*/
public Reduced(
final Iterable<T> values,
final BiFunc<? super T, ? super T, ? extends T> reduce
) {
this(reduce, new Mapped<>(Constant::new, values));
}

/**
* Ctor.
* @param reduce Reducing function
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/cactoos/scalar/ReducedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ public void lastAtIterable() {
).affirm();
}

@Test
public void lastAtIterableOfValues() {
final Character one = 'A';
final Character two = 'B';
final Character three = 'O';
new Assertion<>(
"Must find the last character",
new Reduced<>(
new IterableOf<>(one, two, three),
(first, last) -> last
),
new HasValue<>(three)
).affirm();
}

@Test
public void constructedFromVarargs() {
final String one = "One";
Expand Down

0 comments on commit ff947ea

Please sign in to comment.