I suggest we ...

Add ofObj to Seq and Array

The Option module defines Option.ofObj which converts a potential nullable value to an option.

Collections (Seq and array) can be null in interop scenarios, but it'd often be natural to interpret a null collection as an empty collection.

It's possible to compose such behaviour from existing building blocks, e.g. with Option.ofObj >> Option.toArray >> Array.concat

This seems like quite a roundabout way to do things, so I'd like to propose equivalent functions for Seq and Array:

// seq<'a> -> seq<'a>
Seq.ofObj

// 'a [] -> 'a []
Array.ofObj

6 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Mark SeemannMark Seemann shared this idea  ·   ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Loic DenuziereLoic Denuziere commented  · 

        Alternatively for something more general, we could have a null equivalent of `defaultArg`. So if it's called let's say `ifNull` (placeholder name, not actual proposal) then your `Seq.ofObj s` would be `ifNull s Seq.empty`, and `Array.ofObj s` would be `ifNull s [||]`.

      F# Language

      Feedback and Knowledge Base