org.pkl.thirdparty.paguro.function.Fn0 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkl-config-java-all Show documentation
Show all versions of pkl-config-java-all Show documentation
Shaded fat Jar for pkl-config-java, a Java config library based on the Pkl config language.
// Copyright 2015-03-06 PlanBase Inc. & Glen Peterson
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.pkl.thirdparty.paguro.function;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
/**
This is like Java 8's java.util.function.Supplier, but retrofitted to turn checked exceptions
into unchecked ones. It's also called a thunk when used to delay evaluation.
*/
@FunctionalInterface
public interface Fn0 extends Supplier, Callable {
/** Implement this one method and you don't have to worry about checked exceptions. */
U applyEx() throws Exception;
/**
The class that takes a consumer as an argument uses this convenience method so that it
doesn't have to worry about checked exceptions either.
*/
default U apply() {
try {
return applyEx();
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** {@inheritDoc} */
@Override default U get() { return apply(); }
/** {@inheritDoc} */
@Override default U call() throws Exception { return applyEx(); }
// ========================================== Static ==========================================
// Enums are serializable. Anonymous classes and lambdas are not.
// Dear Glen,
// You have implemented this twice now. There are 3 reasons to leave it commented out:
// 1. `() -> none` is brief, clear, and beautiful.
// 2. You hate the method reference syntax (it's ambiguous).
// 3. Encourage using Option over null.
// /** One-of-a-kind Fn0's. */
// enum ConstObj implements Fn0
© 2015 - 2024 Weber Informatics LLC | Privacy Policy