pydash icon indicating copy to clipboard operation
pydash copied to clipboard

Take while does not support generators

Open Drvanon opened this issue 2 years ago • 0 comments

If I add a generator as the object of my chain and I use the take_while function, it tries to call the nth index of the generator which is not supported.

A suggesteion for this would be

def take_while(array, predicate=None):
    array = list(array)
    n = 0
    for is_true, _, _, _ in iteriteratee(array, predicate):
         if is_true:
             n += 1
         else:
             break
      return array[:n]

or

def take_while(array, predicate=None):
    new_array = []
    while True:
         is_true, n, _, _ in iteriteratee(array, predicate):
         if not is_true:
             break  
         new_array.append(array[n])
    return new_array

Drvanon avatar Aug 01 '23 08:08 Drvanon