- Delphi Cookbook
- Daniele Spinetti Daniele Teti
- 143字
- 2025-04-04 16:22:47
There's more...
Higher-order functions are a vast and interesting topic, so in this recipe we only scratched the surface. One of the main concepts is the abstraction of the internal loop over the data structure. Consider this by abstracting the concept of looping, you can implement looping; any way you want, including implementing it in a way that scales nicely with extra hardware. A good sample of what can be done using functional programming is the parallel extension of the OmniThreadLibrary (a nice library that simplifies multithreading programming), written by Primo? Gabrijel?i? (http://www.thedelphigeek.com/). This is a simple code sample that executes a parallel function for defining a single iteration with an anonymous method and runs it using multiple threads:
Parallel.ForEach(1, 100000).Execute( procedure (Const elem: integer) begin //check if the current element is //a prime number (can be slow) if IsPrime(elem) then MyOutputList.Add(elem); end);