@Override default boolean allMatch(final Predicate<? super Tuple2<K, V>> c) { return Folds.super.allMatch(c); }
default <U> Option<T> maxBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.maxBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default <U extends Comparable<? super U>> Option<T> maxBy(Function<? super T, ? extends U> function){
default <U extends Comparable<? super U>> Option<T> maxBy(Function<? super T, ? extends U> function){ return maxBy(function, Comparator.naturalOrder()); } default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function){
/** * Print each value in this Folds to the console in turn (left-to-right) */ default void printOut() { stream().printOut(); }
@Test public void testMinByMaxBy() { Supplier<Folds<Integer>> s = () -> of(1, 2, 3, 4, 5, 6); assertEquals(1, (int) s.get().maxBy(t -> Math.abs(t - 5)).orElse(-1)); assertEquals(5, (int) s.get().minBy(t -> Math.abs(t - 5)).orElse(-1)); assertEquals(6, (int) s.get().maxBy(t -> "" + t).orElse(-1)); assertEquals(1, (int) s.get().minBy(t -> "" + t).orElse(-1)); }
public void testFoldLeft() { for(int i=0;i<100;i++){ Supplier<Folds<String>> s = () -> of("a", "b", "c"); assertTrue(s.get().foldLeft("", String::concat).contains("a")); assertTrue(s.get().foldLeft("", String::concat).contains("b")); assertTrue(s.get().foldLeft("", String::concat).contains("c")); assertEquals(3, (int) s.get().foldLeft(0, (u, t) -> u + t.length())); assertEquals(3, (int) s.get().foldRight(0, (t, u) -> u + t.length())); } }
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function){ return minBy(function, Comparator.naturalOrder()); } default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){
default NonEmptyList<T> nonEmptyList(Supplier<T> s){ Iterator<T> it = iterator(); return NonEmptyList.cons(it.hasNext() ? it.next() : s.get(), LazySeq.fromIterator(it)); }
default Option<T> median(){ return atPercentile(50.0); }
@Test public void testAnyMatchFalse(){ assertThat(of(1,2,3,4,5).anyMatch(it-> it.equals(8)),is(false)); } @Test
/** * Collect the collectable into a {@link LinkedHashSet}. */ default Set<T> toSet(){ return stream().collect(Collectors.toSet()); } default <R1, R2, A1, A2> Tuple2<R1, R2> collect(Collector<? super T, A1, R1> c1, Collector<? super T, A2, R2> c2) {
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function){ return minBy(function, Comparator.naturalOrder()); } default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){
default NonEmptyList<T> nonEmptyList(Supplier<T> s){ Iterator<T> it = iterator(); return NonEmptyList.cons(it.hasNext() ? it.next() : s.get(), LazySeq.fromIterator(it)); }
default Option<T> median(){ return atPercentile(50.0); }
@Test public void testAnyMatch(){ assertThat(of(1,2,3,4,5).anyMatch(it-> it.equals(3)),is(true)); } @Test
/** * <pre> * {@code * assertEquals("123".length(),ReactiveSeq.of(1, 2, 3).join().length()); * } * </pre> * * @return Stream as concatenated String */ default String join() { return stream().join(); }
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.minBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default Option<T> mode(){
@Test public void testAllMatch(){ assertThat(of(1,2,3,4,5).allMatch(it-> it>0 && it <6),is(true)); } @Test
default <U extends Comparable<? super U>> Option<T> maxBy(Function<? super T, ? extends U> function){ return maxBy(function, Comparator.naturalOrder()); } default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function){