Skip to content

Implement List.choose, Seq.tryPick, etc. for valueoption #6467

@cmeeren

Description

@cmeeren

(This post has been edited 2019-04-23 to constrain/concretize the functions I'd like to be implemented.)

The ValueOption module now has feature parity with Option. That's great! But there's a lot of other functions in other modules that use Option, where ValueOption might provide better performance by avoiding unneeded allocations. I am primarily concerned with having ValueOption equivalents of the following functions:

  • List.choose / Seq.choose / Array.choose
  • List.pick / Seq.pick / Array.pick
  • List.tryPick / Seq.tryPick / Array.tryPick
  • List.unfold / Seq.unfold / Array.unfold

These are arguably the most useful to implement, since they (potentially) allocate one option object for each item. If further prioritization is needed, then I'd guess choose and tryPick are the most commonly used.

(For the sake of completeness: Additional functions in these modules that could be implemented too are all the tryX functions that return an option, but in this issue, I choose to concentrate only on the above.)

I might be able to submit a PR if I get some general guidance on what to add where (never contributed code to FSharp.Core before). For example, should I duplicate existing functions but use ValueSome/ValueNone, or should old functions delegate to new functions in some way, etc. (I suppose the performance will be best with completely separate definitions.) But I'm more than happy to let other people take it, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions