Reputation: 61
How to defined a function that generates a sequence by from the sequence passed as the third argument by taking the number of values passed as the first arguments and applying the the function passed as a second argument to them.
dependingOnPastValues : int -> (int list -> int) -> seq<int> -> seq<int>
The missing past values at the start of the sequence can be considered to be 0.
let dependingOnPastValues (count:int) (fn : int list -> int) (input:seq<int>) : seq<int> = failwith "pseudoRandom not yet implemented!"
Upvotes: 1
Views: 70
Reputation: 1721
How about this:
let dependingOnPastValues numValues mapper seqInput =
seqInput
|> Seq.take numValues
|> mapper
or maybe this:
let dependingOnPastValues numValues mapper seqInput =
seqInput
|> Seq.take numValues
|> Seq.map (fun x -> mapper numValues x)
or perhaps more like this:
let aMapper numValues x =
x // TODO: do something with x
let dependingOnPastValues numValues mapper seqInput =
seqInput
|> Seq.mapi (fun i x ->
if i > numValues then
mapper numValues x
else 0
)
let result =
seq [1;1;2]
|> dependingOnPastValues 1 aMapper
Upvotes: 3