Given the predicate "p", which says the solution is good enough. The cost function is "f", which indicates how well the possible solution is, and the function that searches for the "best" (that is, low cost) solution in the sequence of possible solutions. As an idiomatic way to cancel an estimate - in case the predicate guarantees that the current solution is "good enough" - it looks like this.
i.e. something like that:
let search pf solutionSpace = solutionSpace |> Seq.map (fun x -> fx, x) |> Seq.ignoreAllFollowingElementsWhenPredicateIsTrue (fun (c, s) -> pc) |> Seq.minBy (fun (c, _) -> c)
source share