There are things that have been committed here.
This commit is contained in:
17
optionals/.project
Normal file
17
optionals/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>optionals</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
2
optionals/.settings/org.eclipse.core.resources.prefs
Normal file
2
optionals/.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
11
optionals/.settings/org.eclipse.jdt.core.prefs
Normal file
11
optionals/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=21
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=21
|
42
optionals/src/optionals/Main.java
Normal file
42
optionals/src/optionals/Main.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package optionals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
class OptionalUtils {
|
||||||
|
// Return the list of `f()` applied to every element in `xs`, but do not
|
||||||
|
// include the empty results.
|
||||||
|
static <X, Y> List<Y>
|
||||||
|
convertPassing(List<X> xs, Function<X, Optional<Y>> f) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the list of `f()` applied to every element in `xs`, but do not
|
||||||
|
// include the resuslts that don't pass `pred()`.
|
||||||
|
static <X, Y> List<Y>
|
||||||
|
convertPassing(List<X> xs, Function<X, Y> f, Predicate<Y> pred) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop all empty values.
|
||||||
|
static <X> List<X> dropEmpty(List<Optional<X>> xs) {
|
||||||
|
return xs.stream().filter(Optional::isEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a new function that applies `f()` to non-null values and returns
|
||||||
|
// empty optionals on null values.
|
||||||
|
static <X, Y> Function<X, Optional<Y>> nullFriendly(Function<X, Y> f) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply and to the boolean values if both are present, otherwise return
|
||||||
|
// empty optional.
|
||||||
|
static Optional<Boolean>
|
||||||
|
optionalAnd(Optional<Boolean> b1, Optional<Boolean> b2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Examples {}
|
Reference in New Issue
Block a user