@Override default <U> U foldRight(U zero, BiFunction<? super Tuple2<K, V>, ? super U, ? extends U> f) { Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); }
/** * Iterates this Map sequentially, mapping the (key, value) pairs to elements. * * @param mapper A function that maps (key, value) pairs to elements of type U * @param <U> The type of the resulting elements * @return An iterator through the mapped elements. */ default <U> Iterator<U> iterator(BiFunction<K, V, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return iterator().map(t -> mapper.apply(t._1, t._2)); }
/** * Returns the keys contained in this map as an iterator. * * @return {@code Iterator} of the keys contained in this map. */ default Iterator<K> keysIterator() { return iterator().map(Tuple2::_1); }
@Override default <U, R> Seq<R> zipWith(Iterable<? extends U> that, BiFunction<? super Tuple2<K, V>, ? super U, ? extends R> mapper) { Objects.requireNonNull(that, "that is null"); Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWith(that, mapper)); }
static <K, V, U, M extends Map<K, V>> M distinctBy( M map, OfEntries<K, V, M> ofEntries, Function<? super Tuple2<K, V>, ? extends U> keyExtractor) { Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return ofEntries.apply(map.iterator().distinctBy(keyExtractor)); }
@Override default <T1, T2, T3> Tuple3<Seq<T1>, Seq<T2>, Seq<T3>> unzip3( Function<? super Tuple2<K, V>, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return iterator().unzip3(unzipper).map(Stream::ofAll, Stream::ofAll, Stream::ofAll); }
@Override default <U> Seq<U> zipWithIndex(BiFunction<? super Tuple2<K, V>, ? super Integer, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWithIndex(mapper)); }
static <K, V, M extends Map<K, V>> M distinctBy(M map, OfEntries<K, V, M> ofEntries, Comparator<? super Tuple2<K, V>> comparator) { Objects.requireNonNull(comparator, "comparator is null"); return ofEntries.apply(map.iterator().distinctBy(comparator)); }
static <K, V, M extends Map<K, V>> M filter(M map, OfEntries<K, V, M> ofEntries, Predicate<? super Tuple2<K, V>> predicate) { Objects.requireNonNull(predicate, "predicate is null"); return ofEntries.apply(map.iterator().filter(predicate)); }
@Override default <T1, T2> Tuple2<Seq<T1>, Seq<T2>> unzip(Function<? super Tuple2<K, V>, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return iterator().unzip(unzipper).map(Stream::ofAll, Stream::ofAll); }
static <K, V, M extends Map<K, V>> M dropWhile(M map, OfEntries<K, V, M> ofEntries, Predicate<? super Tuple2<K, V>> predicate) { Objects.requireNonNull(predicate, "predicate is null"); return ofEntries.apply(map.iterator().dropWhile(predicate)); }
@Override default <U> Seq<Tuple2<Tuple2<K, V>, U>> zipAll(Iterable<? extends U> that, Tuple2<K, V> thisElem, U thatElem) { Objects.requireNonNull(that, "that is null"); return Stream.ofAll(iterator().zipAll(that, thisElem, thatElem)); }
/** * Returns <code>true</code> if this map maps one or more keys to the * specified value. This operation will require time linear in the map size. * * @param value value whose presence in this map is to be tested * @return <code>true</code> if this map maps one or more keys to the * specified value */ default boolean containsValue(V value) { return iterator().map(Tuple2::_2).contains(value); }
static <K, V, M extends Map<K, V>> M dropRight(M map, OfEntries<K, V, M> ofEntries, Supplier<M> emptySupplier, int n) { if (n <= 0) { return map; } else if (n >= map.size()) { return emptySupplier.get(); } else { return ofEntries.apply(map.iterator().dropRight(n)); } }
static <K, V, M extends Map<K, V>> M drop(M map, OfEntries<K, V, M> ofEntries, Supplier<M> emptySupplier, int n) { if (n <= 0) { return map; } else if (n >= map.size()) { return emptySupplier.get(); } else { return ofEntries.apply(map.iterator().drop(n)); } }
static <K, V, M extends Map<K, V>> Tuple2<M, M> partition(M map, OfEntries<K, V, M> ofEntries, Predicate<? super Tuple2<K, V>> predicate) { Objects.requireNonNull(predicate, "predicate is null"); final Tuple2<Iterator<Tuple2<K, V>>, Iterator<Tuple2<K, V>>> p = map.iterator().partition(predicate); return Tuple.of(ofEntries.apply(p._1), ofEntries.apply(p._2)); }
static <K, V, M extends Map<K, V>> M takeRight(M map, OfEntries<K, V, M> ofEntries, int n) { if (n >= map.size()) { return map; } else { return ofEntries.apply(map.iterator().takeRight(n)); } }
static <K, V, M extends Map<K, V>> M takeWhile(M map, OfEntries<K, V, M> ofEntries, Predicate<? super Tuple2<K, V>> predicate) { Objects.requireNonNull(predicate, "predicate is null"); final M taken = ofEntries.apply(map.iterator().takeWhile(predicate)); return taken.size() == map.size() ? map : taken; }
static <K, V, M extends Map<K, V>> M take(M map, OfEntries<K, V, M> ofEntries, int n) { if (n >= map.size()) { return map; } else { return ofEntries.apply(map.iterator().take(n)); } }