@@ -665,6 +671,66 @@ static R letWith(final V value,
return block.asUnchecked().apply(value);
}
+ /**
+ * Performs given function block on given value and returns result.
+ *
{@code
+ * int value = letWith("1234", it -> {
+ * System.out.println(it);
+ * return Integer.parseInt(it);
+ * });
+ * }
+ *
+ * @param value the value
+ * @param block the function block
+ * @param the type of the value
+ * @return result
+ */
+ static int letIntWith(final V value,
+ final ThToIntFunction super V, ?> block) {
+ blockArgNotNull(block);
+ return block.asUnchecked().apply(value);
+ }
+
+ /**
+ * Performs given function block on given value and returns result.
+ *
{@code
+ * long value = letWith("1234", it -> {
+ * System.out.println(it);
+ * return Long.parseLong(it);
+ * });
+ * }
+ *
+ * @param value the value
+ * @param block the function block
+ * @param the type of the value
+ * @return result
+ */
+ static long letLongWith(final V value,
+ final ThToLongFunction super V, ?> block) {
+ blockArgNotNull(block);
+ return block.asUnchecked().apply(value);
+ }
+
+ /**
+ * Performs given function block on given value and returns result.
+ *
+ *
+ * @param value the value
+ * @param block the function block
+ * @param the type of the value
+ * @return result
+ */
+ static double letDoubleWith(final V value,
+ final ThToDoubleFunction super V, ?> block) {
+ blockArgNotNull(block);
+ return block.asUnchecked().apply(value);
+ }
+
/**
* Performs given function block on {@link AutoCloseable} value, close this value and returns result.
*
{@code
diff --git a/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java
new file mode 100644
index 0000000..1bf7b44
--- /dev/null
+++ b/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2024 Evgenii Plugatar
+ *
+ * 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 com.plugatar.jkscope.function;
+
+/**
+ * The {@link java.util.function.Function} specialization that produces a {@code double}-valued result and might throw
+ * an exception
+ *
+ * @param the type of the input argument
+ * @param the type of the throwing exception
+ * @see java.util.function.Function
+ */
+@FunctionalInterface
+public interface ThToDoubleFunction {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param t the input argument
+ * @return result
+ * @throws E if function threw exception
+ */
+ double apply(T t) throws E;
+
+ /**
+ * Returns this functions as an unchecked functions.
+ *
+ * @return unchecked function
+ */
+ @SuppressWarnings("unchecked")
+ default ThToDoubleFunction asUnchecked() {
+ return (ThToDoubleFunction) this;
+ }
+}
diff --git a/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java
new file mode 100644
index 0000000..772eca8
--- /dev/null
+++ b/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2024 Evgenii Plugatar
+ *
+ * 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 com.plugatar.jkscope.function;
+
+/**
+ * The {@link java.util.function.Function} specialization that produces an {@code int}-valued result and might throw an
+ * exception
+ *
+ * @param the type of the input argument
+ * @param the type of the throwing exception
+ * @see java.util.function.Function
+ */
+@FunctionalInterface
+public interface ThToIntFunction {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param t the input argument
+ * @return result
+ * @throws E if function threw exception
+ */
+ int apply(T t) throws E;
+
+ /**
+ * Returns this functions as an unchecked functions.
+ *
+ * @return unchecked function
+ */
+ @SuppressWarnings("unchecked")
+ default ThToIntFunction asUnchecked() {
+ return (ThToIntFunction) this;
+ }
+}
diff --git a/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java
new file mode 100644
index 0000000..65e1c01
--- /dev/null
+++ b/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2024 Evgenii Plugatar
+ *
+ * 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 com.plugatar.jkscope.function;
+
+/**
+ * The {@link java.util.function.Function} specialization that produces a {@code long}-valued result and might throw an
+ * exception
+ *
+ * @param the type of the input argument
+ * @param the type of the throwing exception
+ * @see java.util.function.Function
+ */
+@FunctionalInterface
+public interface ThToLongFunction {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param t the input argument
+ * @return result
+ * @throws E if function threw exception
+ */
+ long apply(T t) throws E;
+
+ /**
+ * Returns this functions as an unchecked functions.
+ *
+ * @return unchecked function
+ */
+ @SuppressWarnings("unchecked")
+ default ThToLongFunction asUnchecked() {
+ return (ThToLongFunction) this;
+ }
+}
diff --git a/src/test/java/com/plugatar/jkscope/JKScopeTest.java b/src/test/java/com/plugatar/jkscope/JKScopeTest.java
index ebf769d..f758b64 100644
--- a/src/test/java/com/plugatar/jkscope/JKScopeTest.java
+++ b/src/test/java/com/plugatar/jkscope/JKScopeTest.java
@@ -34,6 +34,9 @@
import com.plugatar.jkscope.function.ThPredicate;
import com.plugatar.jkscope.function.ThRunnable;
import com.plugatar.jkscope.function.ThSupplier;
+import com.plugatar.jkscope.function.ThToDoubleFunction;
+import com.plugatar.jkscope.function.ThToIntFunction;
+import com.plugatar.jkscope.function.ThToLongFunction;
import com.plugatar.jkscope.function.ThTriConsumer;
import com.plugatar.jkscope.function.ThTriFunction;
import org.junit.jupiter.api.Test;
@@ -470,6 +473,33 @@ void letWithStaticMethodThrowsNPEForNullArg() {
.isInstanceOf(NullPointerException.class);
}
+ @Test
+ void letIntWithStaticMethodThrowsNPEForNullArg() {
+ final Object value = new Object();
+ final ThToIntFunction