Null Option Workflow.

25 views
Skip to first unread message

Jay Tuley

unread,
Apr 19, 2018, 5:40:15 PM4/19/18
to fsharp-o...@googlegroups.com
So I've been getting annoyed with not having a packaged (if not standardized) null/option/nullable workflow.

So I decided to make a library.  Naming is a bit challenging, clearly it's an F# only library, so FSharp.BlahBlah.Something. The only BlahBlah example wise that would make sense would be FSharp.Core ¯\_(ツ)_/¯, so I made it FSharp.Core.Experimental.OptionBuilder. I feel like that is dubious, but I'd like some feedback on what the second category of the name should be if otherwise.

The implementation of the actual OptionBuilder (option {}) is pretty much wrapping the Option module functions. I have Bind and ReturnFrom overloads for 'T option, 'T Nullable and 'T when 'T:null.  I added Try/Finally/Using but didn't include any enumeration, it just didn't make sense for a reasonable work flow of  something would return a single option type.

However, a null work flow for a collection of items was still desirable. So I made an addtional builder as part of this library. chooseSeq {}, which was substantially more complex. Similarly it has overloads for Bind and YieldFrom for 'T option'T Nullable and 'T when 'T:null.  The results from yield are combined into a sequence when yield! is not None, Nullable or null.  I also added YieldFrom overloads for 'T seq and string, that flatten sequences like just like seq {}, but I'm unsure if I've inadvertently caused any problems by doing this.  Finally I made chooseSeq a delayed sequence, just like seq.

I'd be really interested in some feedback. Especially if I've went an incorrect direction naming wise.

The project is here:

I haven't put it on nuget mainly because of the name, however I have a myget feed:

Finally here are some examples that I've adapted from else where:

Thanks! 

Jay Tuley

Jay Tuley

unread,
Apr 29, 2018, 2:15:14 PM4/29/18
to fsharp-o...@googlegroups.com
I ended up changing the name for emphasis of interop with null and nullable.


In addition to the option { } and chooseSeq { } computational expressions, i've added some operators |?-> for defaultWith and |>? for bind, that are overloaded to work with _:null, _ option, and _ Nullable interchangably.
Reply all
Reply to author
Forward
0 new messages