8000 Lead, Lag & Window behavior are incoherent · Issue #632 · morelinq/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lead, Lag & Window behavior are incoherent #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Orace opened this issue Nov 1, 2019 · 3 comments
Open

Lead, Lag & Window behavior are incoherent #632

Orace opened this issue Nov 1, 2019 · 3 comments

Comments

@Orace
Copy link
Contributor
Orace commented Nov 1, 2019

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.

@Orace Orace changed the title Lead, Lag and Window behavior are not coherant. [DISCUTION] Lead, Lag and Window behavior are not coherant. Nov 1, 2019
@Orace Orace changed the title [DISCUTION] Lead, Lag and Window behavior are not coherant. [discussion] Lead, Lag and Window behavior are not coherant. Nov 1, 2019
@Orace Orace mentioned this issue Nov 1, 2019
@Orace
Copy link
Contributor Author
Orace commented Nov 1, 2019

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.

@atifaziz
Copy link
Member
atifaziz commented Nov 2, 2019
8000

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.

@atifaziz atifaziz changed the title [discussion] Lead, Lag and Window behavior are not coherant. Lead, Lag & Window behavior are not coherent Nov 2, 2019
@Orace
Copy link
Contributor Author
Orace commented Nov 2, 2019

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.

  • Lead and Lag provide values external of the sequence.
  • WindowLeft and WindowsRight just 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.

@atifaziz atifaziz changed the title Lead, Lag & Window behavior are not coherent Lead, Lag & Window behavior are incoherent Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0