Skip to content

Take while does not support generators #204

@Drvanon

Description

@Drvanon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions