Nullable.AsOption

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

Description

Converts a System.Nullable to an F# Option.

Details

Double click on the code to select all.

 

;