Skip to content
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

Remove tail items while condition is true #1036

Open
atifaziz opened this issue Nov 13, 2023 · 0 comments · May be fixed by #1085
Open

Remove tail items while condition is true #1036

atifaziz opened this issue Nov 13, 2023 · 0 comments · May be fixed by #1085

Comments

@atifaziz
Copy link
Member

Consider adding an operator that remove items from the tail end of a sequence while a given predicate returns true. The proposed name and signature would be:

public static IEnumerable<T> SkipLastWhile<T>(this IEnumerable<T> source, Func<T, bool> predicate)

Example:

var xs = new[]
{
    1, 2,
    0, 0, // will be preserved (not in tail position)
    3, 4,
    0, 0, // will be removed
};

var result = xs.SkipLastWhile(x => x is 0);

Console.WriteLine(result.ToDelimitedString(", "));

Output:

1, 2, 0, 0, 3, 4
ArmoryNode added a commit to ArmoryNode/MoreLINQ that referenced this issue Oct 22, 2024
@ArmoryNode ArmoryNode linked a pull request Oct 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant