3 people like it.

Option.either

I think the following function is useful allowing you to do an Option.map + defaultArg in one go (plus defaultArg argument order is a little annoying). Might need a better name.

1: 
2: 
3: 
4: 
module Option =
    let either f x = function
        | None -> x
        | Some v -> f v
module Option

from Microsoft.FSharp.Core
val either : f:('a -> 'b) -> x:'b -> _arg1:'a option -> 'b

Full name: Script.Option.either
val f : ('a -> 'b)
val x : 'b
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
val v : 'a
Raw view Test code New version

More information

Link:http://fssnip.net/kl
Posted:10 years ago
Author:David Grenier
Tags: option