Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take while does not support generators #204

Open
Drvanon opened this issue Aug 1, 2023 · 0 comments
Open

Take while does not support generators #204

Drvanon opened this issue Aug 1, 2023 · 0 comments

Comments

@Drvanon
Copy link

Drvanon commented Aug 1, 2023

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
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

No branches or pull requests

1 participant