In the folder function of the Array.Fold operation, i want to look back arbitrary number of items.
The only way i can figure out is like this.
let aFolder (dataArray, curIdx, result) (dataItem) =
let N = numItemsToLookBack(result, dataItem)
let recentNitems = dataArray.[curIdx - N .. curIdx - 1]
let result = aCalc(result, dataItem, recentNitems )
dataArray, curIdx + 1, result
myDataArray |> Array.fold aFolder (myDataArray, 0, initResult)
As you can see, I passed the whole dataArray and index to the folder function to get the "recentNitems". But this way allows the folder function to access not only preceding data, but also the following data.
Is there a way to prevent this looking forward thing? Or, is there a better (more functional or more efficient) way regardless of this looking forward problem?