Colouring problem :
Hello, I\'m trying to implement a bool function that returns true when a color can be extended to a country and false otherwise but I\'m having troub
To check that no element in a collection satisfies a given condition: that's not a job for fold
, but, with appropriate negation, for exists
or forall
.
Either of
let fornone f = Set.forall (f >> not)
let doesnotexist f = Set.exists f >> not
will do, as shown in the answer of FuleSnabel. However, it is certainly possible to build these functions from a fold
, albeit nobody would do that except as an illustration of currying, function composition and pointfree style.
let fornone f = Set.fold (fun s -> f >> not >> (&&) s) true
let doesnotexist f = Set.fold (fun s -> f >> (||) s) false >> not