Skip to content

Conversation

DanOpcode
Copy link

Implementation of ZipMap proposed in #661.

@viceroypenguin
Copy link
Contributor

FYI: This operator has been included in SuperLinq 4.0.0, which has now been published.

Copy link
Member

@atifaziz atifaziz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matachi Thanks for contributing this and sorry for having taken so long to get back with a review. Usually, I don't pay attention to a new PR unless the CI build errors are fixed. Anyway, since master had moved on considerably since this PR was opened, I've aligned it with a merge and added my review. Hope you'll find the time to address the comments soon.

/// ("foo", false"), ("bar", true) and ("baz", true), in turn.
/// </example>

public static IEnumerable<(TSource Item, TResult Result)> ZipMap<TSource, TResult>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first tuple element should be named Source or Input instead of Item. Thoughts?

Comment on lines +55 to +58
foreach (var item in source)
{
yield return (item, func(item));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NullArgumentTest tests are breaking. The fix is to validate the arguments eagerly and wrap the iterator in a local function as follows (otherwise arguments are validated when the sequence is iterated rather than when ZipMap is called):

Suggested change
foreach (var item in source)
{
yield return (item, func(item));
}
return _(); IEnumerable<(TSource, TResult)> _()
{
foreach (var item in source)
{
yield return (item, func(item));
}
}

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 this pull request may close these issues.

3 participants