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

[Proposal] Add Interleave overloads. #697

Open
Orace opened this issue Nov 14, 2019 · 0 comments
Open

[Proposal] Add Interleave overloads. #697

Orace opened this issue Nov 14, 2019 · 0 comments

Comments

@Orace
Copy link
Contributor

Orace commented Nov 14, 2019

Given an input of type IEnumerable<IEnumerable<T>> its hard to call Interleave on it:

Enumerable.Empty<T>.Interleave(input);
input.First().Interleave(input.Skip(1));

I propose to add an Interleave overload as a classic static method:

 public static IEnumerable<T> Interleave<T>(IEnumerable<IEnumerable<T>> otherSequences);

// usage
MoreEnumerable.Interleave(input);

Or as an extension method:

 public static IEnumerable<T> Interleave<T>(this IEnumerable<IEnumerable<T>> otherSequences);

// usage
input.Interleave();

We can also add an overload with the SelecMany pattern:

 public static IEnumerable<TResult> Interleave<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector);

// usage
new [] {"AAA", "BBB", "CCC"}.Interleave(e => e); // 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'
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