Hi Jeff,

The Seq module can now be used on the F# list type since F#'s lists now implment the IEnumerable interface. This provides some library functions that allow you to do want you want more concisely and efficiently. How about this:

1
2
3
4
#light
let myList = [1 .. 4]
let l = Seq.take (myList.Length - 1) myList 
printfn "%A" l

Note that Seq also has a truncate function that returns a seq instead of a list. Alteratively you could use a ResizeArray, the F# name for System.Collections.Generic.List. This would be slightly less eligant and less in the functional style, but I think slightly more efficient.

1
2
3
4
#light
let myList =  new ResizeArray<int>([1 .. 4])
myList.RemoveAt(myList.Count - 1)
printfn "%A" myList

Cheers,
Rob

By on 7/27/2007 12:58 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