2 people like it.

Nullable to Option

it's allways a pain to work with F#'s Option values outside of F# - there you've got the Nullable-class this is a short snippet to convert Nullable<'a> to 'a option

let NullableToOption (n : System.Nullable<_>) = 
   if n.HasValue 
   then Some n.Value 
   else None
val NullableToOption : n:System.Nullable<'a> -> 'a option (requires default constructor and value type and 'a :> System.ValueType)

Full name: Script.NullableToOption
val n : System.Nullable<'a> (requires default constructor and value type and 'a :> System.ValueType)
namespace System
Multiple items
type Nullable =
  static member Compare<'T> : n1:Nullable<'T> * n2:Nullable<'T> -> int
  static member Equals<'T> : n1:Nullable<'T> * n2:Nullable<'T> -> bool
  static member GetUnderlyingType : nullableType:Type -> Type

Full name: System.Nullable

type Nullable<'T (requires default constructor and value type and 'T :> ValueType)> =
    new : value:'T -> Nullable<'T>
    member Equals : other:obj -> bool
    member GetHashCode : unit -> int
    member GetValueOrDefault : unit -> 'T + 1 overload
    member HasValue : bool
    member ToString : unit -> string
    member Value : 'T

Full name: System.Nullable<_>

System.Nullable(value: 'T) : unit
property System.Nullable.HasValue: bool
union case Option.Some: Value: 'T -> Option<'T>
property System.Nullable.Value: 'a
union case Option.None: Option<'T>
Raw view New version

More information

Posted:5 years ago
Author:Carsten K├Ânig
Tags: nullable , option