Hide this comment

I might write it like this:

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

let exceptionToOption f x =
    try Some(f x)
    with _ -> None

let convert fConvert s =
    s |> Seq.map (exceptionToOption fConvert)
      |> Seq.choose id

convert System.Int32.Parse ["1"; "two"; "3"]
|> printfn "%A"

By on 4/30/2010 6:11 PM ()Reply
Hide this comment

Brian,

I'd simplify that to:

1
2
3
4
let convert fConvert s =
    s |> Seq.choose (exceptionToOption fConvert)

By on 4/30/2010 7:14 PM ()Reply
Hide this comment

That looks okay to me. One improvement would be to use Seq.choose in place of the last two pipes.

By on 4/30/2010 4:55 PM ()Reply
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

Logging in...