Reputation: 59
So how can i implement "any"(Haskell) to java?
The "any" haskell code:
any p = foldr' (\x y -> p x || y) False
and my first try is this, but i dont know how i write p x
in java.
boolean any(List<A> xs) {
return foldr(x -> y -> x==y || y, false, xs);
}
Upvotes: 1
Views: 88
Reputation: 2044
You would write p(x)
, BUT your Java implementation doesn't take p
as an argument. I think your signature should be
boolean any (Predicate<? super A> p, List<A> xs)
Upvotes: 2