From aecc7ab045810c9ad0843843e6276fc82dc194fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Kope=C4=87?= Date: Sat, 8 Nov 2025 15:33:36 +0100 Subject: [PATCH] Fix: Missing type overrides for .mapTo and .mapToVoid --- vavr/src/main/java/io/vavr/Lazy.java | 10 ++++++++++ vavr/src/main/java/io/vavr/Value.java | 2 ++ vavr/src/main/java/io/vavr/collection/Array.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/BitSet.java | 10 ++++++++++ .../src/main/java/io/vavr/collection/CharSeq.java | 10 ++++++++++ .../src/main/java/io/vavr/collection/HashSet.java | 10 ++++++++++ .../main/java/io/vavr/collection/IndexedSeq.java | 10 ++++++++++ .../main/java/io/vavr/collection/Iterator.java | 10 ++++++++++ .../main/java/io/vavr/collection/LinearSeq.java | 10 ++++++++++ .../java/io/vavr/collection/LinkedHashSet.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/List.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Map.java | 10 ++++++++++ .../main/java/io/vavr/collection/Multimap.java | 10 ++++++++++ .../java/io/vavr/collection/PriorityQueue.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Queue.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Seq.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Set.java | 10 ++++++++++ .../main/java/io/vavr/collection/SortedSet.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Stream.java | 10 ++++++++++ .../main/java/io/vavr/collection/Traversable.java | 10 ++++++++++ vavr/src/main/java/io/vavr/collection/Tree.java | 10 ++++++++++ .../src/main/java/io/vavr/collection/TreeSet.java | 15 ++++++++++----- vavr/src/main/java/io/vavr/collection/Vector.java | 10 ++++++++++ vavr/src/main/java/io/vavr/concurrent/Future.java | 10 ++++++++++ vavr/src/main/java/io/vavr/control/Option.java | 9 +++++++++ vavr/src/main/java/io/vavr/control/Try.java | 10 ++++++++++ vavr/src/test/java/io/vavr/collection/IntMap.java | 10 ++++++++++ .../test/java/io/vavr/collection/IntMultimap.java | 10 ++++++++++ 28 files changed, 271 insertions(+), 5 deletions(-) diff --git a/vavr/src/main/java/io/vavr/Lazy.java b/vavr/src/main/java/io/vavr/Lazy.java index 2e95dccac0..23ea57c10c 100644 --- a/vavr/src/main/java/io/vavr/Lazy.java +++ b/vavr/src/main/java/io/vavr/Lazy.java @@ -223,6 +223,16 @@ public Lazy map(Function mapper) { return Lazy.of(() -> mapper.apply(get())); } + @Override + public Lazy mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Lazy mapToVoid() { + return map(ignored -> null); + } + @Override public Lazy peek(Consumer action) { action.accept(get()); diff --git a/vavr/src/main/java/io/vavr/Value.java b/vavr/src/main/java/io/vavr/Value.java index 5d6fbda2f3..1895f592fd 100644 --- a/vavr/src/main/java/io/vavr/Value.java +++ b/vavr/src/main/java/io/vavr/Value.java @@ -70,6 +70,8 @@ *
  • {@link #getOrElseTry(CheckedFunction0)}
  • *
  • {@link #getOrNull()}
  • *
  • {@link #map(Function)}
  • + *
  • {@link #mapTo(Object)}
  • + *
  • {@link #mapToVoid()}
  • *
  • {@link #stringPrefix()}
  • * * diff --git a/vavr/src/main/java/io/vavr/collection/Array.java b/vavr/src/main/java/io/vavr/collection/Array.java index 35d93d1d03..739c3ef61a 100644 --- a/vavr/src/main/java/io/vavr/collection/Array.java +++ b/vavr/src/main/java/io/vavr/collection/Array.java @@ -971,6 +971,16 @@ public Array map(Function mapper) { return wrap(arr); } + @Override + public Array mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Array mapToVoid() { + return map(ignored -> null); + } + @Override public Array orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/collection/BitSet.java b/vavr/src/main/java/io/vavr/collection/BitSet.java index 7ad5838f2d..ba895921e4 100644 --- a/vavr/src/main/java/io/vavr/collection/BitSet.java +++ b/vavr/src/main/java/io/vavr/collection/BitSet.java @@ -588,6 +588,16 @@ default SortedSet map(Function mapper) { return map(Comparators.naturalComparator(), mapper); } + @Override + default SortedSet mapTo(U value) { + return map(ignored -> value); + } + + @Override + default SortedSet mapToVoid() { + return map(ignored -> null); + } + @Override BitSet remove(T element); diff --git a/vavr/src/main/java/io/vavr/collection/CharSeq.java b/vavr/src/main/java/io/vavr/collection/CharSeq.java index f494c5736e..73613d5cad 100644 --- a/vavr/src/main/java/io/vavr/collection/CharSeq.java +++ b/vavr/src/main/java/io/vavr/collection/CharSeq.java @@ -668,6 +668,16 @@ public IndexedSeq map(Function mapper) { return result; } + @Override + public IndexedSeq mapTo(U value) { + return map(ignored -> value); + } + + @Override + public IndexedSeq mapToVoid() { + return map(ignored -> null); + } + @Override public String mkString() { return back; diff --git a/vavr/src/main/java/io/vavr/collection/HashSet.java b/vavr/src/main/java/io/vavr/collection/HashSet.java index f2367a57a8..119a9aab45 100644 --- a/vavr/src/main/java/io/vavr/collection/HashSet.java +++ b/vavr/src/main/java/io/vavr/collection/HashSet.java @@ -714,6 +714,16 @@ public HashSet map(Function mapper) { } } + @Override + public HashSet mapTo(U value) { + return map(ignored -> value); + } + + @Override + public HashSet mapToVoid() { + return map(ignored -> null); + } + @Override public String mkString(CharSequence prefix, CharSequence delimiter, CharSequence suffix) { return iterator().mkString(prefix, delimiter, suffix); diff --git a/vavr/src/main/java/io/vavr/collection/IndexedSeq.java b/vavr/src/main/java/io/vavr/collection/IndexedSeq.java index dd52624cc0..538a5d4ec0 100644 --- a/vavr/src/main/java/io/vavr/collection/IndexedSeq.java +++ b/vavr/src/main/java/io/vavr/collection/IndexedSeq.java @@ -230,6 +230,16 @@ default int lastIndexWhere(Predicate predicate, int end) { @Override IndexedSeq map(Function mapper); + @Override + default IndexedSeq mapTo(U value) { + return map(ignored -> value); + } + + @Override + default IndexedSeq mapToVoid() { + return map(ignored -> null); + } + @Override IndexedSeq orElse(Iterable other); diff --git a/vavr/src/main/java/io/vavr/collection/Iterator.java b/vavr/src/main/java/io/vavr/collection/Iterator.java index 796af83bbd..359a95bba8 100644 --- a/vavr/src/main/java/io/vavr/collection/Iterator.java +++ b/vavr/src/main/java/io/vavr/collection/Iterator.java @@ -1701,6 +1701,16 @@ public U getNext() { } } + @Override + default Iterator mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Iterator mapToVoid() { + return map(ignored -> null); + } + @Override default Iterator orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/collection/LinearSeq.java b/vavr/src/main/java/io/vavr/collection/LinearSeq.java index 4988c0a6c2..2db401e754 100644 --- a/vavr/src/main/java/io/vavr/collection/LinearSeq.java +++ b/vavr/src/main/java/io/vavr/collection/LinearSeq.java @@ -212,6 +212,16 @@ default int lastIndexWhere(Predicate predicate, int end) { @Override LinearSeq map(Function mapper); + @Override + default LinearSeq mapTo(U value) { + return map(ignored -> value); + } + + @Override + default LinearSeq mapToVoid() { + return map(ignored -> null); + } + @Override LinearSeq orElse(Iterable other); diff --git a/vavr/src/main/java/io/vavr/collection/LinkedHashSet.java b/vavr/src/main/java/io/vavr/collection/LinkedHashSet.java index 05359f7fc9..516cbacc31 100644 --- a/vavr/src/main/java/io/vavr/collection/LinkedHashSet.java +++ b/vavr/src/main/java/io/vavr/collection/LinkedHashSet.java @@ -735,6 +735,16 @@ public LinkedHashSet map(Function mapper) { } } + @Override + public LinkedHashSet mapTo(U value) { + return map(ignored -> value); + } + + @Override + public LinkedHashSet mapToVoid() { + return map(ignored -> null); + } + @Override public String mkString(CharSequence prefix, CharSequence delimiter, CharSequence suffix) { return iterator().mkString(prefix, delimiter, suffix); diff --git a/vavr/src/main/java/io/vavr/collection/List.java b/vavr/src/main/java/io/vavr/collection/List.java index 82a2c1aa8c..0e858233ee 100644 --- a/vavr/src/main/java/io/vavr/collection/List.java +++ b/vavr/src/main/java/io/vavr/collection/List.java @@ -1056,6 +1056,16 @@ default List map(Function mapper) { return list.reverse(); } + @Override + default List mapTo(U value) { + return map(ignored -> value); + } + + @Override + default List mapToVoid() { + return map(ignored -> null); + } + @Override default List orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/collection/Map.java b/vavr/src/main/java/io/vavr/collection/Map.java index 00511f6ff8..1c76227b5f 100644 --- a/vavr/src/main/java/io/vavr/collection/Map.java +++ b/vavr/src/main/java/io/vavr/collection/Map.java @@ -424,6 +424,16 @@ default Seq map(Function, ? extends U> mapper) { return (Seq) iterator().map(mapper).toStream(); } + @Override + default Seq mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Seq mapToVoid() { + return map(ignored -> null); + } + /** * Maps the entries of this {@code Map} to form a new {@code Map}. * diff --git a/vavr/src/main/java/io/vavr/collection/Multimap.java b/vavr/src/main/java/io/vavr/collection/Multimap.java index 19b446aae0..3d317ec334 100644 --- a/vavr/src/main/java/io/vavr/collection/Multimap.java +++ b/vavr/src/main/java/io/vavr/collection/Multimap.java @@ -410,6 +410,16 @@ default Seq map(Function, ? extends U> mapper) { return (Seq) iterator().map(mapper).toStream(); } + @Override + default Seq mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Seq mapToVoid() { + return map(ignored -> null); + } + /** * Maps the values of this {@code Multimap} while preserving the corresponding keys. * diff --git a/vavr/src/main/java/io/vavr/collection/PriorityQueue.java b/vavr/src/main/java/io/vavr/collection/PriorityQueue.java index 45df0eccf1..b7b13b43cc 100644 --- a/vavr/src/main/java/io/vavr/collection/PriorityQueue.java +++ b/vavr/src/main/java/io/vavr/collection/PriorityQueue.java @@ -464,6 +464,16 @@ public PriorityQueue map(Function mapper) { return map(Comparators.naturalComparator(), mapper); } + @Override + public PriorityQueue mapTo(U value) { + return map(ignored -> value); + } + + @Override + public PriorityQueue mapToVoid() { + return map(ignored -> null); + } + public PriorityQueue map(Comparator comparator, Function mapper) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(mapper, "mapper is null"); diff --git a/vavr/src/main/java/io/vavr/collection/Queue.java b/vavr/src/main/java/io/vavr/collection/Queue.java index 329a8e21a9..3c405de853 100644 --- a/vavr/src/main/java/io/vavr/collection/Queue.java +++ b/vavr/src/main/java/io/vavr/collection/Queue.java @@ -994,6 +994,16 @@ public Queue map(Function mapper) { return new Queue<>(front.map(mapper), rear.map(mapper)); } + @Override + public Queue mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Queue mapToVoid() { + return map(ignored -> null); + } + @Override public Queue orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/collection/Seq.java b/vavr/src/main/java/io/vavr/collection/Seq.java index 2f1200791c..2355dd54ee 100644 --- a/vavr/src/main/java/io/vavr/collection/Seq.java +++ b/vavr/src/main/java/io/vavr/collection/Seq.java @@ -1216,6 +1216,16 @@ default U foldRight(U zero, BiFunction f) @Override Seq map(Function mapper); + @Override + default Seq mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Seq mapToVoid() { + return map(ignored -> null); + } + @Override Seq orElse(Iterable other); diff --git a/vavr/src/main/java/io/vavr/collection/Set.java b/vavr/src/main/java/io/vavr/collection/Set.java index 8507995f00..9bd24a1cd9 100644 --- a/vavr/src/main/java/io/vavr/collection/Set.java +++ b/vavr/src/main/java/io/vavr/collection/Set.java @@ -248,6 +248,16 @@ default boolean isDistinct() { @Override Set map(Function mapper); + @Override + default Set mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Set mapToVoid() { + return map(ignored -> null); + } + @Override Set orElse(Iterable other); diff --git a/vavr/src/main/java/io/vavr/collection/SortedSet.java b/vavr/src/main/java/io/vavr/collection/SortedSet.java index a816e5ca98..f94a48c253 100644 --- a/vavr/src/main/java/io/vavr/collection/SortedSet.java +++ b/vavr/src/main/java/io/vavr/collection/SortedSet.java @@ -149,6 +149,16 @@ default boolean isOrdered() { @Override SortedSet map(Function mapper); + @Override + default SortedSet mapTo(U value) { + return map(ignored -> value); + } + + @Override + default SortedSet mapToVoid() { + return map(ignored -> null); + } + @Override SortedSet orElse(Iterable other); diff --git a/vavr/src/main/java/io/vavr/collection/Stream.java b/vavr/src/main/java/io/vavr/collection/Stream.java index a65f018a75..b131388e7f 100644 --- a/vavr/src/main/java/io/vavr/collection/Stream.java +++ b/vavr/src/main/java/io/vavr/collection/Stream.java @@ -1236,6 +1236,16 @@ default Stream map(Function mapper) { } } + @Override + default Stream mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Stream mapToVoid() { + return map(ignored -> null); + } + @Override default Stream padTo(int length, T element) { if (length <= 0) { diff --git a/vavr/src/main/java/io/vavr/collection/Traversable.java b/vavr/src/main/java/io/vavr/collection/Traversable.java index d522fe985c..c7f4a54cf5 100644 --- a/vavr/src/main/java/io/vavr/collection/Traversable.java +++ b/vavr/src/main/java/io/vavr/collection/Traversable.java @@ -808,6 +808,16 @@ default Option lastOption() { @Override Traversable map(Function mapper); + @Override + default Traversable mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Traversable mapToVoid() { + return map(ignored -> null); + } + /** * Calculates the maximum of this elements according to their natural order. Especially the underlying * order of sorted collections is not taken into account. diff --git a/vavr/src/main/java/io/vavr/collection/Tree.java b/vavr/src/main/java/io/vavr/collection/Tree.java index 80c17cbb03..8e49d2bd0f 100644 --- a/vavr/src/main/java/io/vavr/collection/Tree.java +++ b/vavr/src/main/java/io/vavr/collection/Tree.java @@ -629,6 +629,16 @@ default Tree map(Function mapper) { return isEmpty() ? Empty.instance() : TreeModule.map((Node) this, mapper); } + @Override + default Tree mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Tree mapToVoid() { + return map(ignored -> null); + } + @Override default Tree orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/collection/TreeSet.java b/vavr/src/main/java/io/vavr/collection/TreeSet.java index bcd08ba28f..6f282a07e5 100644 --- a/vavr/src/main/java/io/vavr/collection/TreeSet.java +++ b/vavr/src/main/java/io/vavr/collection/TreeSet.java @@ -771,6 +771,16 @@ public TreeSet map(Function mapper) { return map(Comparators.naturalComparator(), mapper); } + @Override + public TreeSet mapTo(U value) { + return map(ignored -> value); + } + + @Override + public TreeSet mapToVoid() { + return map((o1, o2) -> 0, ignored -> null); + } + /** * Returns this {@code TreeSet} if it is nonempty, * otherwise {@code TreeSet} created from iterable, using existing comparator. @@ -1017,11 +1027,6 @@ public SortedSet zipWithIndex(BiFunction mapToVoid() { - return map((o1, o2) -> 0, ignored -> null); - } - // -- Object @Override diff --git a/vavr/src/main/java/io/vavr/collection/Vector.java b/vavr/src/main/java/io/vavr/collection/Vector.java index 7af303ab1c..8aeca8c56d 100644 --- a/vavr/src/main/java/io/vavr/collection/Vector.java +++ b/vavr/src/main/java/io/vavr/collection/Vector.java @@ -869,6 +869,16 @@ public Vector map(Function mapper) { return ofAll(trie.map(mapper)); } + @Override + public Vector mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Vector mapToVoid() { + return map(ignored -> null); + } + @Override public Vector orElse(Iterable other) { return isEmpty() ? ofAll(other) : this; diff --git a/vavr/src/main/java/io/vavr/concurrent/Future.java b/vavr/src/main/java/io/vavr/concurrent/Future.java index 2a9adf6c35..08b2e51612 100644 --- a/vavr/src/main/java/io/vavr/concurrent/Future.java +++ b/vavr/src/main/java/io/vavr/concurrent/Future.java @@ -1282,6 +1282,16 @@ default Future map(Function mapper) { return transformValue(t -> t.map(mapper)); } + @Override + default Future mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Future mapToVoid() { + return map(ignored -> null); + } + default Future mapTry(CheckedFunction1 mapper) { Objects.requireNonNull(mapper, "mapper is null"); return transformValue(t -> t.mapTry(mapper)); diff --git a/vavr/src/main/java/io/vavr/control/Option.java b/vavr/src/main/java/io/vavr/control/Option.java index f197d110c9..07458ae453 100644 --- a/vavr/src/main/java/io/vavr/control/Option.java +++ b/vavr/src/main/java/io/vavr/control/Option.java @@ -390,6 +390,15 @@ default Option map(Function mapper) { return isEmpty() ? none() : some(mapper.apply(get())); } + @Override + default Option mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Option mapToVoid() { + return map(ignored -> null); + } /** * Converts this to a {@link Try}, then runs the given checked function if this is a {@link Try.Success}, diff --git a/vavr/src/main/java/io/vavr/control/Try.java b/vavr/src/main/java/io/vavr/control/Try.java index 9b4c0a7266..1ba9c9c12a 100644 --- a/vavr/src/main/java/io/vavr/control/Try.java +++ b/vavr/src/main/java/io/vavr/control/Try.java @@ -583,6 +583,16 @@ default Try map(Function mapper) { return mapTry(mapper::apply); } + @Override + default Try mapTo(U value) { + return map(ignored -> value); + } + + @Override + default Try mapToVoid() { + return map(ignored -> null); + } + /** * Maps the cause to a new exception if this is a {@code Failure} or returns this instance if this is a {@code Success}. *

    diff --git a/vavr/src/test/java/io/vavr/collection/IntMap.java b/vavr/src/test/java/io/vavr/collection/IntMap.java index 9c690c0647..a8dd3348f3 100644 --- a/vavr/src/test/java/io/vavr/collection/IntMap.java +++ b/vavr/src/test/java/io/vavr/collection/IntMap.java @@ -223,6 +223,16 @@ public Seq map(Function mapper) { return original.map(e -> mapper.apply(e._2)); } + @Override + public Seq mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Seq mapToVoid() { + return map(ignored -> null); + } + @Override public IntMap orElse(Iterable other) { return unit(original.orElse(List.ofAll(other).zipWithIndex().map(t -> Tuple.of(t._2, t._1)))); diff --git a/vavr/src/test/java/io/vavr/collection/IntMultimap.java b/vavr/src/test/java/io/vavr/collection/IntMultimap.java index 7ad3cdfdc2..3786118dc2 100644 --- a/vavr/src/test/java/io/vavr/collection/IntMultimap.java +++ b/vavr/src/test/java/io/vavr/collection/IntMultimap.java @@ -224,6 +224,16 @@ public Seq map(Function mapper) { return original.map(e -> mapper.apply(e._2)); } + @Override + public Seq mapTo(U value) { + return map(ignored -> value); + } + + @Override + public Seq mapToVoid() { + return map(ignored -> null); + } + @Override public IntMultimap orElse(Iterable other) { return unit(original.orElse(List.ofAll(other).zipWithIndex().map(t -> Tuple.of(t._2, t._1))));