Repository navigation
Description
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 failsinstead of
if fails |> Array.isEmpty |> not then
logFails failsor
if not (Array.isEmpty fails) then
logFails failsor
if (not << Array.isEmpty) fails then
logFails fails
Activity
gusty commentedon Sep 16, 2026
Not to my knowledge, so let's open it there as well fsprojects/FSharpPlus#683
My favs are the same as yours ;)
TheAngryByrd commentedon Sep 17, 2026
I also usually have “filterOut” instead of reject but because of its location with intellisense
Sounds like good additiona
bartelink commentedon Sep 17, 2026
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
Notas 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, 🎉 forfilterNot, ❤️ forfilterOut?bartelink commentedon Sep 18, 2026
Hm I also needed an Option.reject and then logically you want an Option.none to go with it
... and same for ValueOption
TheAngryByrd commentedon Sep 18, 2026
Yeah this just goes back to our previous conversation, everyone has their favorite alias :)