1
2
3
4
5
6
7
8
9
10
11
12
13
14
 

let transform stateF initialState f data =
  let rec transformAux state data acc = 
    match data with
    | hd :: tl ->
        let transformedValue = f state hd
        let transformedState = stateF state transformedValue
        transformAux transformedState tl (transformedValue :: acc)
    | [] -> List.rev acc
  transformAux initialState data []

transform (fun state x -> state + x) 1 (fun state x -> x * state) [1;2;3;4;5;6]

just in case... it is not a standard function though

By on 8/24/2009 8:10 AM ()

Sounds like Seq.unfold may also be a relevant function to look at.

-Keith

By on 8/23/2009 12:28 PM ()

You might want to check out Seq.pairwise and Seq.windowed

[link:research.microsoft.com]

though I don't think either does exactly what you describe here.

You might also check out

[link:cs.hubfs.net]

and linked threads.

By on 8/23/2009 9:32 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper