SHARE
TWEET

Untitled

a guest Sep 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public static class EnumeratorExtensions
  5. {
  6.     public static IEnumerable<T> TakeNextUntil<T>(this IEnumerator<T> enumerator, Predicate<T> predicate)
  7.     {
  8.         while(enumerator.MoveNext())
  9.         {
  10.             var item = enumerator.Current;
  11.             if (predicate(item))
  12.                 break;
  13.             yield return item;
  14.         }
  15.     }
  16.    
  17.     public static T TakeNextItem<T>(this IEnumerator<T> enumerator) =>
  18.             enumerator.MoveNext()? enumerator.Current : throw new Exception("Cannot retrieve next item");
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top