Why use a BiFunction
when the desired interface was a BiPredicate
?
#176
Labels
BiFunction
when the desired interface was a BiPredicate
?
#176
Describe the feature request
In the
Unleash
interface, there are some methods with aBiFunction<String, UnleashContext, Boolean>
argument. But the availables implementations forUnleash
(DefaultUnleash
,FakeUnleash
) both have no safe measures against this function returning anull
. Bot will yield aNullPointerException
:DefaultUnleash.java#L123-L127
FakeUnleash.java#L43-L46
:Also, it is more semantic to use
Predicate<T>
or similar instead ofFunction<T, Boolean>
or similar.Background
Using
Predicate<T>
instead ofFunction<T, Boolean>
is a lot more semantic, and also avoids (some) random null pointer exceptions that the java type system allows.If the null pointer exception happens for some reason, it will be a violation of contract of the API consumer, not of the API provider, as it is now.
Solution suggestions
Change the API to accept a
BiPredicate
instead of aBiFunction
.It is wildly expected that it shall be ok with the use of lambdas. It will break compatibility if someone passes directly an instance of
BiFunction<String, UnleashContext, Boolean>
, as the tests within here have broken.Trying to accept both
BiPredicate<String, UnleashContext>
andBiFunction<String, UnleashContext, Boolean>
will cause the compiler to get confused, as both will satisfy the lambda signature. For example, inDefaultUnleash
will yield a compiler error:This will require a manual action of the maintainer to specify that it is a
BiPredicate
that it is wanted:The text was updated successfully, but these errors were encountered: