I have a sequential process with an additional exit condition. One way to write algorithms:
let mutable more = true for slot = startSlot to endSlot do if more then more <- process()
The overhead of checking more for slots skipped due to exit is not significant. However, there seems to be a more elegant way of expressing this.
more
Recursion is usually used here:
let rec loop slot = if slot <= endSlot && process () then loop (slot + 1) loop startSlot
The compiler will reduce this to a simple loop (the actual recursion fails).
One way to do this is to use Seq.takeWhile
Seq.takeWhile
seq{startSlot .. endSlot} |> Seq.takeWhile (fun _ -> process()) |> Seq.iter ignore
This will exit the loop when process() returns false
process()
false
Source: https://habr.com/ru/post/1264456/More articles:Where can you find the control panel for xampp on mac? - xamppAngular 2 + Jasmine - check if an element is visible - unit-testingthis.setState () does not work in the WillReceiveProps component - reactjsHow to use maximum field rating in table script - ElasticSearch - groovyBottomNavigationBar - change the color of the tab icon - androidDoes constexpr move constructor make sense? - c ++How to use saveesSuperviewLayoutMargins in nested views - iosFirebase Permanent Authentication on Device - iosAngular 2 (Angular-cli): Not Prepared ReferenceError: google undefined - angularHow to add a button to a sidebar widget? - htmlAll Articles