https://github.com/ekonbenefits/fsharp.interop.nulloptable
Missing OptionBuilder for F# filling the void to interop with C#'s ?. usage
https://github.com/ekonbenefits/fsharp.interop.nulloptable
fsharp monads null nullable option
Last synced: about 15 hours ago
JSON representation
Missing OptionBuilder for F# filling the void to interop with C#'s ?. usage
- Host: GitHub
- URL: https://github.com/ekonbenefits/fsharp.interop.nulloptable
- Owner: ekonbenefits
- License: mit
- Created: 2018-04-14T01:22:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-15T21:54:36.000Z (11 months ago)
- Last Synced: 2025-09-08T18:45:44.932Z (29 days ago)
- Topics: fsharp, monads, null, nullable, option
- Language: F#
- Homepage: https://ekonbenefits.github.io/FSharp.Interop.NullOptAble/
- Size: 320 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FSharp.Interop.NullOptAble [](https://www.nuget.org/packages/FSharp.Interop.NullOptAble/)
Missing OptionBuilder for F# filling the void to interop with C#'s `?.` usage.
It works with Nulls, Options, Nullables.CI Builds available: [](https://www.myget.org/feed/ci-fsharp-optionbuilder/package/nuget/FSharp.Interop.NullOptAble)
Build Statuses:
* Windows: [](https://ci.appveyor.com/project/jbtule/fsharp-interop-nulloptable/branch/master)
* Mac & Linux: [](https://travis-ci.org/ekonbenefits/FSharp.Interop.NullOptAble)## 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
```fsharp
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](https://ekonbenefits.github.io/FSharp.Interop.NullOptAble/RealWorld.html).### Operator Examples
This library also has some operators available when specifically included
```fsharp
using FSharp.Interop.NullOptAble.Operators
```
You can find examples of them in [Tests/RealWorldOperators.fs](https://ekonbenefits.github.io/FSharp.Interop.NullOptAble/RealWorldOperators.html).