R sneakyThrow(Throwable t) throws T {
80 | throw (T) t;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/GwtIncompatible.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2018 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr;
20 |
21 | import java.lang.annotation.*;
22 |
23 | @Retention(RetentionPolicy.CLASS)
24 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
25 | @Documented
26 | @interface GwtIncompatible {
27 | String value() default "";
28 | }
29 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/MatchError.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr;
20 |
21 | import java.util.NoSuchElementException;
22 |
23 | /**
24 | * A {@link API.Match} throws a MatchError if no case matches the applied object.
25 | *
26 | * @author Daniel Dietrich
27 | */
28 | public class MatchError extends NoSuchElementException {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | @SuppressWarnings("serial") // Conditionally serializable
33 | private final Object obj;
34 |
35 | /**
36 | * Internally called by {@link API.Match}.
37 | *
38 | * @param obj The object which could not be matched.
39 | */
40 | MatchError(Object obj) {
41 | super((obj == null) ? "null" : "type: " + obj.getClass().getName() + ", value: " + obj);
42 | this.obj = obj;
43 | }
44 |
45 | /**
46 | * Returns the object which could not be matched.
47 | *
48 | * @return An Object.
49 | */
50 | public Object getObject() {
51 | return obj;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/Memoized.java:
--------------------------------------------------------------------------------
1 | package io.vavr;
2 |
3 | /**
4 | * INTERNAL. Zero abstract method (ZAM) / tagging interface.
5 | */
6 | interface Memoized {
7 | }
8 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/NotImplementedError.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr;
20 |
21 | /**
22 | * This exception is temporarily used during development in order to indicate that an implementation is missing.
23 | *
24 | * The idiomatic way is to use one of {@link API#TODO()} and {@link API#TODO(String)}.
25 | */
26 | public class NotImplementedError extends Error {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Creates a {@code NotImplementedError} containing the message "an implementation is missing".
32 | */
33 | public NotImplementedError() {
34 | super("An implementation is missing.");
35 | }
36 |
37 | /**
38 | * Creates a {@code NotImplementedError} containing the given {@code message}.
39 | *
40 | * @param message A text that describes the error
41 | */
42 | public NotImplementedError(String message) {
43 | super(message);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/AbstractIterator.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.collection;
20 |
21 | import java.util.NoSuchElementException;
22 |
23 | /**
24 | * Provides a common {@link Object#toString()} implementation.
25 | *
26 | * {@code equals(Object)} and {@code hashCode()} are intentionally not overridden in order to prevent this iterator
27 | * from being evaluated. In other words, (identity-)equals and hashCode are implemented by Object.
28 | *
29 | * @param Component type
30 | * @author Daniel Dietrich
31 | */
32 | abstract class AbstractIterator implements Iterator {
33 |
34 | @Override
35 | public String toString() {
36 | return stringPrefix() + "(" + (isEmpty() ? "" : "?") + ")";
37 | }
38 |
39 | protected abstract T getNext();
40 |
41 | @Override
42 | public final T next() {
43 | if (!hasNext()) {
44 | throw new NoSuchElementException("next() on empty iterator");
45 | }
46 | return getNext();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/Comparators.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.collection;
20 |
21 | import java.io.Serializable;
22 | import java.util.Comparator;
23 |
24 | /**
25 | * INTERNAL: Common {@code Comparator} related functions (not intended to be public).
26 | *
27 | * @author Daniel Dietrich
28 | */
29 | final class Comparators {
30 |
31 | private Comparators() {
32 | }
33 |
34 | /**
35 | * Returns the natural comparator for type U, i.e. treating it as {@code Comparable}.
36 | * The returned comparator is also {@code java.io.Serializable}.
37 | *
38 | * Please note that this will lead to runtime exceptions, if U is not Comparable.
39 | *
40 | * @param The type
41 | * @return The natural Comparator of type U
42 | */
43 | @SuppressWarnings("unchecked")
44 | static Comparator naturalComparator() {
45 | return NaturalComparator.instance();
46 | }
47 | }
48 |
49 | final class NaturalComparator implements Comparator, Serializable {
50 |
51 | private static final long serialVersionUID = 1L;
52 |
53 | private static final NaturalComparator> INSTANCE = new NaturalComparator<>();
54 |
55 | private NaturalComparator() {
56 | }
57 |
58 | @SuppressWarnings("unchecked")
59 | static NaturalComparator instance() {
60 | return (NaturalComparator) INSTANCE;
61 | }
62 |
63 | @SuppressWarnings("unchecked")
64 | @Override
65 | public int compare(T o1, T o2) {
66 | return ((Comparable) o1).compareTo(o2);
67 | }
68 |
69 | /** @see Comparator#equals(Object) */
70 | @Override
71 | public boolean equals(Object obj) {
72 | return obj instanceof NaturalComparator;
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | return 1;
78 | }
79 |
80 | /**
81 | * Instance control for object serialization.
82 | *
83 | * @return The singleton instance of NaturalComparator.
84 | * @see java.io.Serializable
85 | */
86 | private Object readResolve() {
87 | return INSTANCE;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/GwtIncompatible.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.collection;
20 |
21 | import java.lang.annotation.*;
22 |
23 | @Retention(RetentionPolicy.CLASS)
24 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
25 | @Documented
26 | @interface GwtIncompatible {
27 | String value() default "";
28 | }
29 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/Multimaps.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.collection;
20 |
21 | import io.vavr.Tuple2;
22 | import java.util.Objects;
23 | import java.util.function.Function;
24 |
25 | /**
26 | * INTERNAL: Common {@code Multimap} functions (not intended to be public).
27 | *
28 | * @author Ruslan Sennov, Daniel Dietrich
29 | */
30 | class Multimaps {
31 |
32 | @SuppressWarnings("unchecked")
33 | static > M ofJavaMap(M source, java.util.Map extends K, ? extends V> map) {
34 | Objects.requireNonNull(map, "map is null");
35 | return Stream.ofAll(map.entrySet()).foldLeft(source, (m, el) -> (M) m.put(el.getKey(), el.getValue()));
36 | }
37 |
38 | @SuppressWarnings("unchecked")
39 | static > M ofStream(M source, java.util.stream.Stream extends T> stream,
40 | Function super T, ? extends K> keyMapper,
41 | Function super T, ? extends V> valueMapper) {
42 | Objects.requireNonNull(stream, "stream is null");
43 | Objects.requireNonNull(keyMapper, "keyMapper is null");
44 | Objects.requireNonNull(valueMapper, "valueMapper is null");
45 | return Stream.ofAll(stream).foldLeft(source, (m, el) -> (M) m.put(keyMapper.apply(el), valueMapper.apply(el)));
46 | }
47 |
48 | @SuppressWarnings("unchecked")
49 | static > M ofStream(M source, java.util.stream.Stream extends T> stream,
50 | Function super T, Tuple2 extends K, ? extends V>> entryMapper) {
51 | Objects.requireNonNull(stream, "stream is null");
52 | Objects.requireNonNull(entryMapper, "entryMapper is null");
53 | return Stream.ofAll(stream).foldLeft(source, (m, el) -> (M) m.put(entryMapper.apply(el)));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/Ordered.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.collection;
20 |
21 | import java.util.Comparator;
22 |
23 | /**
24 | * An ordered collection interface.
25 | *
26 | * @param Component type
27 | * @author Ruslan Sennov, Daniel Dietrich
28 | */
29 | public interface Ordered {
30 |
31 | /**
32 | * Returns the comparator which defines the order of the elements contained in this collection.
33 | *
34 | * @return The comparator that defines the order of this collection's elements.
35 | */
36 | Comparator comparator();
37 | }
38 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/collection/readme-contributing.md:
--------------------------------------------------------------------------------
1 | We need to follow some conventions to keep the collections consistent.
2 |
3 | There are two kinds of methods
4 |
5 | - **Accessors** access some of the elements of a collection, but return a result which is unrelated to the collection.
6 | Example of accessors are: head, foldLeft, toList.
7 |
8 | - **Transformers** access elements of a collection and produce a new collection of same type as a result.
9 | Example of transformers are: filter, map, groupBy, zip.
10 |
11 | Given this, our _transformers_ should return the most specific type, e.g. `HashMap.map(...)` should return `HashMap`. E.g. `zipWithIndex` is also a transformer.
12 |
13 | Our _accessors_ should return an interface instead to keep our library extensible for future enhancements. E.g. `HashMap.groupBy` should return `Map` because we may decide in future that returning another Map implementation than HashMap is more efficient. Returning now HashMap would break API on future changes. The only disadvantage is that Map's methods have generic parameters with wildcards, which reduces usability slightly.
14 |
15 | More specific, methods like `Seq.combinations()` or `Seq.crossProduct()` should return `Seq`. This applies also to subclasses of `Seq`. E.g. `CharSeq.combinations()` should also return `Seq`. Of course the concrete object returned remains `Vector` (for CharSeq).
16 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/concurrent/GwtIncompatible.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2018 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.concurrent;
20 |
21 | import java.lang.annotation.*;
22 |
23 | @Retention(RetentionPolicy.CLASS)
24 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
25 | @Documented
26 | @interface GwtIncompatible {
27 | String value() default "";
28 | }
29 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/concurrent/Task.java:
--------------------------------------------------------------------------------
1 | package io.vavr.concurrent;
2 |
3 | import io.vavr.control.Try;
4 |
5 | /**
6 | * Represents a possibly asynchronous unit of work, called "Task".
7 | *
8 | * A {@code Task} is a function that takes an instance of {@link Complete} and returns nothing.
9 | *
10 | * {@code Complete} is a handler that needs to be actively called to complete the {@code Task}.
11 | *
12 | *
{@code
13 | * Callable worker = ...;
14 | * Future result = Future.run(complete -> complete.with(Try.of(worker::call)));
15 | * }
16 | *
17 | * @param result type
18 | * @deprecated Experimental API
19 | */
20 | @Deprecated
21 | @FunctionalInterface
22 | public interface Task {
23 |
24 | /**
25 | * Runs the task. Non-fatal errors are catched by a {@link Future}.
26 | *
27 | * @param complete a function that completes this task
28 | * @throws Throwable if an error occurs
29 | */
30 | void run(Complete complete) throws Throwable;
31 |
32 | /**
33 | * Completes a task.
34 | *
35 | * @param result type
36 | */
37 | @FunctionalInterface
38 | interface Complete {
39 |
40 | /**
41 | * A function that takes a {@link Try} (success or failure) and returns the state of completion.
42 | *
43 | * @param value the computation result
44 | * @return {@code true}, if the task could be completed, otherwise {@code false}.
45 | * Successive calls will result in {@code false}.
46 | */
47 | boolean with(Try extends T> value);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/concurrent/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains basic building blocks for creating fast, asynchronous, non-blocking parallel code.
3 | *
4 | * A {@linkplain io.vavr.concurrent.Future} represents an asynchronous task. It is a placeholder for a
5 | * value that becomes available at some point. With the help of {@code Future} we efficiently perform many non-blocking
6 | * operations in parallel. The value of a Future is supplied concurrently and can subsequently be used. Multiple
7 | * concurrent tasks represented by Futures can be composed to a single Future.
8 | */
9 | package io.vavr.concurrent;
10 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/concurrent/readme-contributing.md:
--------------------------------------------------------------------------------
1 | These are the ideas behind the implementation of Future/Promise:
2 |
3 | The design follows separation of concerns in two manners:
4 |
5 | - public interfaces vs. internal implementations (Promise/PromiseImpl, Future/FutureImpl)
6 | - Future = read-only, Promise = write-once
7 |
8 | ### Interfaces vs. internal classes
9 |
10 | Concurrent programming is all about synchronized state. To keep this as simple as possible, it is a good idea to
11 | separate readable and writable state. The internal implementations encapsulate the state. Their number of methods
12 | drill down to those which access instance variables. These classes are typically very short. They represent a
13 | clean and easy to maintain, thread-safe core.
14 |
15 | The interfaces define, beside abstract methods, static factory methods, static extension methods and default methods.
16 | The default implementations are built on top of the tread-safe core mentioned above. Typically, no additional
17 | synchronization takes place here.
18 |
19 | ### Read-only vs. write-once
20 |
21 | Separating the end-user API into the Future interface, providing the read-only API, and the Promise interface,
22 | providing the write-once API, solves a different concurrency problem than state synchronization. By separating
23 | these concerns, we define a specific _programming model_ that allows us to easily deal with common tasks in
24 | concurrent programming.
25 |
26 | ```java
27 | final Promise promise = Promise.make();
28 | final Future future = promise.future();
29 |
30 | // producer
31 | Future.run(() -> {
32 | promise.success(produceSomething());
33 | continueDoingSomethingUnrelated();
34 | });
35 |
36 | // consumer
37 | Future.run(() -> {
38 | startDoingSomething();
39 | future.onSuccess(doSomethingWithResult);
40 | });
41 | ```
42 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/control/GwtIncompatible.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2018 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr.control;
20 |
21 | import java.lang.annotation.*;
22 |
23 | @Retention(RetentionPolicy.CLASS)
24 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
25 | @Documented
26 | @interface GwtIncompatible {
27 | String value() default "";
28 | }
29 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/control/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Control structures like the disjoint union type {@linkplain io.vavr.control.Either}, the optional value type
3 | * {@linkplain io.vavr.control.Option} and {@linkplain io.vavr.control.Try} for exception handling.
4 | *
5 | * Either
6 | *
7 | * The control package contains an implementation of the {@linkplain io.vavr.control.Either} control which is either Left or Right.
8 | * A given Either is projected to a Left or a Right.
9 | * Both cases can be further processed with control operations map, flatMap, filter.
10 | * If a Right is projected to a Left, the Left control operations have no effect on the Right value.
11 | * If a Left is projected to a Right, the Right control operations have no effect on the Left value.
12 | *
13 | * Option
14 | *
15 | * The Option control is a replacement for {@linkplain java.util.Optional}. An Option is either
16 | * {@linkplain io.vavr.control.Option.Some} value or {@linkplain io.vavr.control.Option.None}.
17 | * In contrast to Optional, Option supports null values, i.e. it is possible to call {@code new Some(null)}.
18 | * However, {@code Option.of(null)} results in None.
19 | *
20 | * Try
21 | *
22 | * Exceptions are handled with the {@linkplain io.vavr.control.Try} control which is either a
23 | * {@linkplain io.vavr.control.Try.Success}, containing a result, or a {@linkplain io.vavr.control.Try.Failure},
24 | * containing an Exception.
25 | */
26 | package io.vavr.control;
27 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Beside {@link io.vavr.API} the io.vavr package contains core types like (Checked)Functions and Tuples.
3 | */
4 | package io.vavr;
5 |
--------------------------------------------------------------------------------
/vavr/src/main/java/io/vavr/readme-contributing.md:
--------------------------------------------------------------------------------
1 | Please ensure that all major types but Functions, currently Tuples, Values and Traversables, have a `transform` method.
2 |
3 | Example (`TYPE` is replaced by the actual type):
4 |
5 | ```java
6 | /**
7 | * Transforms this {@code TYPE}.
8 | *
9 | * @param f A transformation
10 | * @param Type of transformation result
11 | * @return An instance of type {@code U}
12 | * @throws NullPointerException if {@code f} is null
13 | */
14 | default U transform(Function super TYPE super T>, ? extends U> f) {
15 | Objects.requireNonNull(f, "f is null");
16 | return f.apply(this);
17 | }
18 | ```
19 |
20 | See also [#716](https://github.com/vavr-io/vavr/issues/716#issuecomment-163399633).
21 |
--------------------------------------------------------------------------------
/vavr/src/main/javadoc/overview.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | API Overview
5 |
6 |
7 |
This is the documentation for the Vavr library.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/vavr/src/test/java/io/vavr/AssertionsExtensions.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr;
20 |
21 | import java.lang.reflect.Constructor;
22 | import org.assertj.core.api.Assertions;
23 |
24 | public final class AssertionsExtensions {
25 |
26 | private AssertionsExtensions() {
27 | }
28 |
29 | public static ClassAssert assertThat(Class> clazz) {
30 | return new ClassAssert(clazz);
31 | }
32 |
33 | public static class ClassAssert {
34 |
35 | final Class> clazz;
36 |
37 | ClassAssert(Class> clazz) {
38 | this.clazz = clazz;
39 | }
40 |
41 | @SuppressWarnings("deprecation")
42 | public void isNotInstantiable() {
43 | try {
44 | final Constructor> cons = clazz.getDeclaredConstructor();
45 | Assertions.assertThat(cons.isAccessible()).isFalse();
46 | } catch (NoSuchMethodException e) {
47 | throw new AssertionError("no default constructor found");
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/vavr/src/test/java/io/vavr/CheckedPredicateTest.java:
--------------------------------------------------------------------------------
1 | /* ____ ______________ ________________________ __________
2 | * \ \/ / \ \/ / __/ / \ \/ / \
3 | * \______/___/\___\______/___/_____/___/\___\______/___/\___\
4 | *
5 | * Copyright 2014-2025 Vavr, https://vavr.io
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package io.vavr;
20 |
21 | import java.util.function.Predicate;
22 | import org.junit.jupiter.api.Assertions;
23 | import org.junit.jupiter.api.Test;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | public class CheckedPredicateTest {
28 |
29 | // -- of
30 |
31 | @Test
32 | public void shouldCreateCheckedPredicateUsingLambda() {
33 | final CheckedPredicate