Make zipXxxx() functions emptiness-preserving #396

Closed
gavinking opened this Issue Jan 20, 2014 · 1 comment

Comments

Projects
None yet
2 participants
Owner

gavinking commented Jan 20, 2014

Stuff like this:

shared Iterable<Result,A1|A2> mapPairs<Result,FirstArgument,SecondArgument,A1,A2>(
    Result collecting(FirstArgument firstArg, SecondArgument secondArg),
    Iterable<FirstArgument,A1> firstArguments, 
    Iterable<SecondArgument,A2> secondArguments
) given A1 satisfies Null given A2 satisfies Null {
    object iterable satisfies Iterable<Result,A1|A2> {
        shared actual Iterator<Result> iterator() {
            value first = firstArguments.iterator();
            value second = secondArguments.iterator();
            object iterator satisfies Iterator<Result> {
                shared actual Result|Finished next() {
                    if (!is Finished firstArg=first.next(),
                        !is Finished secondArg=second.next()) {
                        return collecting(firstArg,secondArg);
                    }
                    else {
                        return finished;
                    }
                }
            }
            return iterator;
        }
    }
    return iterable;
}

shared Iterable<[First,Second],A1|A2> zipPairs<First,Second,A1,A2>
        (Iterable<First,A1> firstElements, Iterable<Second,A2> secondElements) 
        given A1 satisfies Null given A2 satisfies Null
        => mapPairs((First first,Second second) 
                => [first,second], firstElements, secondElements);

Ugly, but necessary :-/

gavinking was assigned Jan 20, 2014

Member

tombentley commented Mar 24, 2014

Dupe of #340?

gavinking closed this in 772d505 May 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment