DerrAIner
DerrAIner

Reputation: 59

Haskell in java, how can i implement "any"(haskell) in java?

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

Answers (1)

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

Related Questions