Skip to content

Seq/Array/List/Map: Add useful inverses #377

Open

Description

@bartelink

In F# in general, having multiple ways to do things is frowned upon (and I agree).So, for aliases, we have exactly one pair (where vs filter), and don't want any more.

On the other hand, frequently useful inverses make code more legible and expressive; in particular, IME they are useful for tests (esp with unquote), but of course they apply to prod code too.

Proposed inverse Impl sketch Notes
forall (not << exists) (not << predicate) Already in the box
exists (not << forall) (not << predicate) Already in the box
isNotEmpty not << isEmpty Could also be called any (as per LINQ, 3 chars), but Not makes purpose/redundancy clear and puts it nearby in completion list.
reject filter (not << predicate) Could perhaps be called drop, but that's normally a non-throwing skip (in F# it's truncate). Alternate name filterNot. reject name is from Ruby.
none forall (not << predicate) Aligns with reject
isNotEmptyAndForAll isNotEmpty xs && forall predicate xs Alternate names: notEmptyAndAll, existsAndAll, nonEmptyAndAll, nonEmptyAll. Avoids double enumeration and much clearer when piping

My top ones in practice (from Equinox and internal helpers in various codebases) are reject, isNotEmpty and none. I'd be happy with those three being added across the board. Also interested in prior art and pros/cons for suggested names. I'm betting @gusty has insights on that score; is there a stance/has there been a debate in an issue in FSharpPlus?

Example usage

In unquote tests I its useful to be able to say:

test <@ items |> Seq.none _.IsInternal @>
test <@ items |> Seq.reject _.IsInternal |> Seq.isEmpty @>

instead of

test <@ items |> Seq.forall (_.IsInternal >> not) @>
test <@ items |> Seq.filter (_.IsInternal >> not) |> Seq.isEmpty @>

Example usage

if Array.isNotEmpty fails then
    logFails fails

instead of

if fails |> Array.isEmpty |> not then
    logFails fails

or

if not (Array.isEmpty fails) then
    logFails fails

or

if (not << Array.isEmpty) fails then
    logFails fails

Activity

  1. gusty commented on Sep 16, 2026

    @gusty

    is there a stance/has there been a debate in an issue in FSharpPlus?

    Not to my knowledge, so let's open it there as well fsprojects/FSharpPlus#683

    My favs are the same as yours ;)

  2. TheAngryByrd commented on Sep 17, 2026

    @TheAngryByrd
    Collaborator

    I also usually have “filterOut” instead of reject but because of its location with intellisense

    Sounds like good additiona

  3. bartelink commented on Sep 17, 2026

    @bartelink
    ContributorAuthor

    Except is always what I expect it to be called [but that's set oriented in both LINQ and FSharp.Core].

    While filterOut is very intuitive and feels good, I still marginally favor using a Not as it has has prior art and alignment with isNotEmprt / isNotNull?

    Would love to hear other opinions on naming, and which of the above to skip on the basis of being low traffic or just confusing; ultimately these are one liners that won't change the world.

    Maybe vote 👍 for reject, 🎉 for filterNot, ❤️ for filterOut?

  4. bartelink commented on Sep 18, 2026

    @bartelink
    ContributorAuthor

    Hm I also needed an Option.reject and then logically you want an Option.none to go with it
    ... and same for ValueOption

  5. TheAngryByrd commented on Sep 18, 2026

    @TheAngryByrd
    Collaborator

    Yeah this just goes back to our previous conversation, everyone has their favorite alias :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions