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

py_next() implementation does not support optional default value on StopIteration #831

Open
JennaSys opened this issue Oct 31, 2022 · 0 comments

Comments

@JennaSys
Copy link
Collaborator

The Python version of the built-in next() function supports a 2nd argument whose value is returned when the iterator is exhausted instead of raising a StopIteration exception. This 2nd argument is currently ignored by Transcrypt:

export function py_next (iterator) {               // Called only in a Python context, could receive Python or JavaScript iterator
    try {                                   // Primarily assume Python iterator, for max speed
        var result = iterator.__next__ ();
    }
    catch (exception) {                     // JavaScript iterators are the exception here
        var result = iterator.next ();
        if (result.done) {
            throw StopIteration (new Error ());
        }
        else {
            return result.value;
        }
    }
    if (result == undefined) {
        throw StopIteration (new Error ());
    }
    else {
        return result;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant