开发者

about Func.repeatN

There is code in Expert F# like this :

// Perform a CPU-intensive operation on the image.
    pixels |> Func.repeatN processImageRepeats (Array.map (fun b -> b + 1uy))

what is the use of Func.repeatN? it seems its already gone. Is there a function which replace Func.repeatN?

For more information: I did search it on google, there is one appear on top but i can't access this web (my keyword is :Func.RepeatN) : The F# September 2008 Com开发者_运维百科munity Technology Preview, 1.9.6.2 stuff.mit.edu/afs/athena.mit.edu/.../README-fsharp.html - The Permutation module remains in the PowerPack; Func.*, e.g. Func.repeatN deleted; CompatArray and CompatMatrix modules deleted. ...


This is definitely not a standard F# library function.

Unless this is some performance chapter (where the authors just need slower implementation for demonstration purposes), the function should most likely repeatedly apply the specified transformation on the input and then on the result of the previous application. When it reaches zero, it would return the original input unmodified.

The implementation is a simple recursive function:

module Func = 
  let rec repeatN count f input = 
    // Repeating less than zero times - return the input
    if count <= 0 then input
    // Otherwise apply the function once and repeat (count - 1) times
    else repeatN (count - 1) f (f input)

EDIT My original thought (now deleted) was probably wrong (I don't have the book around to check), so this is an improved answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜