Skip to content

Commit

Permalink
Add JavaToScalaTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
qianheng-aws committed Nov 1, 2024
1 parent 3978b19 commit c57254a
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.ppl.utils;


import scala.PartialFunction;
import scala.runtime.AbstractPartialFunction;

public interface JavaToScalaTransformer {
static <T> PartialFunction<T, T> toPartialFunction(
java.util.function.Predicate<T> isDefinedAt,
java.util.function.Function<T, T> apply) {
return new AbstractPartialFunction<T, T>() {
@Override
public boolean isDefinedAt(T t) {
return isDefinedAt.test(t);
}

@Override
public T apply(T t) {
if (isDefinedAt.test(t)) return apply.apply(t);
else return t;
}
};
}
}

0 comments on commit c57254a

Please sign in to comment.