Why do you use Seq.map? String.Split returns string array. You may use Array.map, Array.sort, and Array.nth

By on 2/8/2009 1:31 AM ()

It can be done, but in this case I think you don't want to.

Instead, before sorting, turn the seq into an array, then sort the array, then use Array.find_index.

  • Arrays are better for sorting
  • Array.find_index does what you want

If you do need to do it for a seq, first do "Seq.mapi (fun i x -> i,x)" and then "Seq.find_index" would work.

By on 2/7/2009 10:49 PM ()

Convert it to a list first.

let position = tsorted |> Seq.to_list |> List.find_index (fun value -> value=name)

or a bit shorter:

let position = tsorted |> Seq.to_list |> List.find_index ((=) name)

Which is basically using partial function applicatino. The = operator can be treated like a function. So normally = takes two arguments, but ((=) name) builds a new function that takes 1 argument. It forwards the argument being passed to it as the second argument to operator =, and the first argument to operator = it passes name.

By on 2/7/2009 10:47 PM ()
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