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

Nullable.AsOption

Converts a System.Nullable to an F# Option.

Source

namespace Foo

open System

[<AutoOpen>]
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

Example

let opt = myNullable.AsOption

Author: Joel Mueller

Submitted on: 29 okt 2010

Language: F#

Type: System.Nullable<T>

Views: 3363