wForget commented on PR #1819:
URL:
https://github.com/apache/incubator-uniffle/pull/1819#issuecomment-2185849947
> Maybe we can just use pure Java codes, something like:
>
> ```
> import java.util.concurrent.atomic.AtomicBoolean;
> import java.util.function.Supplier;
>
> public class FunctionUtils {
>
> public static <T> Supplier<T> once(Supplier<T> supplier) {
> return new Supplier<T>() {
> private final AtomicBoolean computed = new
AtomicBoolean(false);
> private T value;
>
> @Override
> public T get() {
> if (computed.compareAndSet(false, true)) {
> value = supplier.get();
> }
> return value;
> }
> };
> }
>
> public static void main(String[] args) {
> Supplier<String> supplier = () -> {
> System.out.println("Called only once");
> return "Hello, World!";
> };
>
> Supplier<String> memoizedSupplier = once(supplier);
>
> System.out.println(memoizedSupplier.get());
> System.out.println(memoizedSupplier.get());
> System.out.println(memoizedSupplier.get());
> }
> }
> ```
>
> Then we can avoid the Scala compatibility issue. WDYT?
`CompletionIterator$.MODULE$.apply` accepts Function0 type
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]