CSBiology / FSharpAux

Auxiliary functions and data structures for the F# programming language
MIT License
23 stars 16 forks source link

[BUG] `Array.groupWhen` returns an empty array if the predicate never returns `true` #19

Closed omaus closed 2 years ago

omaus commented 2 years ago

Description

Array.groupWhen returns an empty array if the predicate never returns true.

Repro steps

  1. Use this exemplary code in a script environment:
    let isOdd = n % 2 <> 0
    Array.groupWhen isOdd [|4;4;2;4;0;2|]
  2. Run the code

Expected behavior

Returns [|[|4;4;2;4;0;2|]|]

Actual behavior

Returns [|[||]|]

Known workarounds

Introduce a case where the predicate returns true. Not well applicable.

Related information

kMutagene commented 2 years ago

Might be arguing about semantics, but this is the correct output i would expect from groupWhen. It opens a new group only if the predicate is true.

omaus commented 2 years ago

No, imo it is not. No grouping applied does, imo, not mean that you get nothing back but that the original, unseparated group is returned as the only resulting subgroup.
Seq.groupWhen and List.groupWhen behave as expected (by me).

Seq.groupWhen isOdd [|6; 6; 2; 4; 2; 8|] // val it: seq<seq<int>> = seq [[6; 6; 2; 4; 2; 8]]
List.groupWhen isOdd [6; 6; 2; 4; 2; 8] // val it: int list list = [[6; 6; 2; 4; 2; 8]]
kMutagene commented 2 years ago

i stand overruled.