There are things that have been committed here.

This commit is contained in:
Jacob Signorovitch
2025-03-03 11:21:06 -05:00
parent b910cad7ba
commit 677b8941e3
4 changed files with 72 additions and 0 deletions

17
optionals/.project Normal file
View 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>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View 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

View 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 {}