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
Open

Remove tail items while condition is true #1036

atifaziz opened this issue Nov 13, 2023 · 0 comments

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
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

No branches or pull requests

1 participant