ExtensionMethod.NET Home of 841 C#, Visual Basic, F# and Javascript extension methods


Converts a System.Nullable to an F# Option.


namespace Foo

open System

module FsExtensions =

    type Nullable<'T when 'T : struct and 'T :> ValueType and 'T:(new: unit -> 'T)> with
        /// Converts a Nullable type into an Option.
        member inline this.AsOption =
if this.HasValue then Some(this.Value) else None


let opt = myNullable.AsOption

Author: Joel Mueller

Submitted on: 29 okt 2010

Language: F#

Type: System.Nullable<T>

Views: 3363