Lead, Lag & Window behavior are incoherent
Lead and Lag return a default value when looking before or after the source sequence.
Window stays in the source sequence.
The difference of behavior is misleading. We may think to homogenize this and have this grammar:
{Lead|Lag|Window}{_|Left|Right|LeftAndRight}
This is a breaking change for current Lead and Lag behavior.
An other option is to made Window relaxed (ie: behave like WindowLeftAndRight) and introduce Strict method.
{Lead|Lag|Window}{_|Left|Right|Strict}
This is a breaking change for current Window
behavior.
The difference of behavior is misleading.
Please expand. You didn't say why apart from that the 3 differ in behaviour and that two require defaults. Each has arguments that pertain to its function.
For readability, I use the not yet merged ValueTuple providing overloads of Lead and Lag.
Current behavior is:
var nums = new[] {1,2,3 };
nums.Lag(1); // [1,0],[2,1],[3,2]
nums.Lead(1); // [1,2],[2,3],[3,0]
nums.Window(2); // [1,2],[2,3]
nums.WindowLeft(2); // [1,2],[2,3],[3]
nums.WindowRight(2); // [1],[1,2],[2,3]
All of this methods are providing pairs of neighbour elements from the original source.
What is misleading for me is the behavior around the first and the last element.
-
LeadandLagprovide values external of the sequence. -
WindowLeftandWindowsRightjust doesn't include it.
What is missing is:
- A window left and right
- A padding value for
Window
And my expected behavior is:
var nums = new[] {1,2,3 };
nums.Lag(1); // [2,1],[3,2]
nums.Lead(1); // [1,2],[2,3]
nums.Window(2); // [1,2],[2,3]
Then add overloads for other needs: (I put the parameters names for readability).
var nums = new[] {1,2,3 };
nums.Lag(1, paddingValue: 0); // [1,0],[2,1],[3,2]
nums.Lead(1, paddingValue: 0); // [1,2],[2,3],[3,0]
nums.Window(2, paddingValue: 0); // [0,1],[1,2],[2,3],[3,0]
WindowLeft and WindowRight should be renamed to enlighten their behaviors.