FSharp.Interop.NullOptAble


FSharp.Interop.NullOptAble NuGet Status

Missing OptionBuilder for F# filling the void to interop with C#'s ?. usage. It works with Nulls, Options, Nullables.

CI Builds available: MyGet Pre Release

Build Statuses:

  • Windows: Build status
  • Mac & Linux: Build Status

Basic Info

There are more C# devs relying on the safe nav operator ?. and so nulls will only get worse on the C# side, making it more likely null's are going to drop out of APIs.

This project creates an option { } computational expression and chooseSeq { } computational expression that allows binding 'T option/'T Nullable/'T:null thus either returns an option or a sequence respectively.

With chooseSeq if you yield! another chooseSeq it will work recursively flatten or any sequence of NonNullSeq, list, or Set type. Any other sequence will be treated like a T:null object yield! and let! work with 'T option/'T Nullable/'T:null

Examples

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let x = Nullable(3)
let y = Nullable(3)
option {
    let! x' = x
    let! y' = y
    return (x' + y')
} |> should equal (Some 6)

See more examples in Tests/RealWorld.fs.

Operator Examples

This library also has some operators available when specifically included

1: 
using FSharp.Interop.NullOptAble.Operators

You can find examples of them in Tests/RealWorldOperators.fs.

val x : obj
val y : obj
type 'T option = Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
val using : resource:'T -> action:('T -> 'U) -> 'U (requires 'T :> System.IDisposable)
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.Interop
namespace FSharp.Interop.NullOptAble
module Operators

from FSharp.Interop.NullOptAble
Fork me on GitHub