MoreLINQ icon indicating copy to clipboard operation
MoreLINQ copied to clipboard

Zip while

Open Orace opened this issue 6 years ago • 2 comments

Depend on #639

ZipWhile allow the user to made custom length Zip.

An example of use is when the user wants to create a zip from a main sequence and a secondary sequence and expect the result to be the length of the main sequence regardless of the length of the secondary sequence.

  // continue zip until first source (users) is consumed
  var usersAndEmail = users.ZipWhile(emails, liveSources => liveSources.Contains(1));

If the secondary sequence is longest that the main sequence, the enumeration of the secondary sequence does not reach end. If the secondary sequence is shortest that the main sequence, the default value is used for padding.

Orace avatar Nov 05 '19 11:11 Orace

I would like to avoid the 1-based status access. My first thought about the predicate was something like that:

  var usersAndEmail = users.ZipWhile(emails, aliveSources => aliveSources .Contains(users));

But I get a warning on users in Contains(users) because it's used while it may have been disposed.

An other option is to expose an object with as many status property as they are enumerable.

  var usersAndEmail = users.ZipWhile(emails, status => status.IsSource1Alive);
  var usersAndEmail = users.ZipWhile(emails, status => status.HasSource1Data);
  var usersAndEmail = users.ZipWhile(emails, status => !status.IsSource1Consumed);

I'm open for propositions here.

Orace avatar Nov 05 '19 20:11 Orace

I don't have enough of the context of your problem to make a call here but something tells me that this is something for Rx and observables (reactive sources), not sequences (interactive sources).

atifaziz avatar Nov 05 '19 20:11 atifaziz

I'm closing this since there's been no follow-up to provide additional context, but reconsider if there's renewed interest to continue the conversation on motivation for this.

atifaziz avatar Oct 21 '23 12:10 atifaziz