Hello, I have a java function with following signa...
# codereview
m
Hello, I have a java function with following signature:
public static ScoreDto score(String email, String name, String surname, Function<String, Boolean> function)
What would be the idiomatic/more readable approach to call it from Kotlin, given that
dataProvider
is a nullable instance of class that implements Function<String, Boolean>?
Copy code
score(
        "<mailto:some_email@domain.com|some_email@domain.com>",
        "John",
        "Doe"
    ) { dataProvider?.apply(it) }
vs
Copy code
score(
        "<mailto:some_email@domain.com|some_email@domain.com>",
        "John",
        "Doe",
        { dataProvider?.apply(it) }
     )
vs
Copy code
dataProvider?.let {
    score(
       "<mailto:some_email@domain.com|some_email@domain.com>"
        "John",
        "Doe",
        it
    )
}
s
The last one has different semantics than the first two. It doesn't call the function if the provider is null. The first is more idiomatic than the second I'd say.
1
m
oh I didn't even realize that. Thank you
m
The first form is definitely the most idiomatic. — side note: the last parameter in the Java signature could be simplified to
Predicate<String> function
.
❤️ 1