Hi,
here is an sample session from the F# interactive that may be useful:

1
2
3
4
5
6
 
> let lines = ["one"; "two"; "three"];;
val lines : string list

> List.mapi (fun idx line -> (idx, line)) lines;;
val it : (int * string) list = [(0, "one"); (1, "two"); (2, "three")]

The List.mapi function takes a function as the first argument. It calls this function for each element from the "lines" list and gives it the index of the item ("idx") and the item from the list ("line"). The example above just returns a tuple that contains the index (unique id) and the original line.

It would be useful to see larger portion of the problem you're trying to solve - for example, you probably wouldn't update the ID property of some object, because when writing code in a functional way, most of the data structures are immutable (which means that you can't change their properties).

Hope this helps!
T.

By on 12/3/2008 9:57 AM ()

Thanks! That was exactly what I was looking for! Your book looks very good. I'll read the free chapter and will probably buy early access.

cheers,
Achim

By on 12/3/2008 10:04 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