On Mon, May 6, 2013 at 1:59 PM, Matthieu Monrocq <[email protected]> wrote: > > And then I realized that "zipfill" can be expressed much more cleanly with > composition instead: > > - zip(cycle(short), long) => cycle through short until long is exhausted, > needs a "stop" > - zip(cycle(short, long.size()), long) => cycle through short until > long.size() elements were served > - zip(fill(short, defval), long) > ... > > > So maybe we could use conditions with a "zip" that is strict by default and > leaves it up to a condition to signal whether to "Stop" or "Fail" when one > list is too short. However there is the issue of "choosing" what that list > is, namely what if I want to "Stop" if the first list is too short, but > would rather "Fail" if it is the second ? > > Furthermore, there is also the issue of the transitive behavior of > conditions. Since "zip" wraps arbitrary iterators, it might wrap an iterator > itself implemented in terms of "zip", and in this case the "condition" set > for the outer "zip" would also be used (unless cancelled) by the inner > "zip". I find it non-obvious. It might point at a more general issue about > (potentially) recursive functions and conditions by the way. > > > So, instead, maybe composition should be used for "zipcut" too. I can > imagine the "take" function of Haskell fitting neatly here: > > - zip(short, take(long, short.size())) => only consider the first > "short.size()" elements of "long" (fails if long is not long enough thus!) > > Though I find it difficult to catter to the case where one list is shorter > than the other, but we cannot know their sizes in advance (I am thinking > streams here). > > > In the end, I would favor having "zip" and "zipcut", and not using > conditions. But maybe that's me :) >
Please consider us mere mortals who know what we want but not all these fancy concepts like "take" and "cycle" and such. Slightly tongue-in-cheek, but in all seriousness, it seems like a complex way express something relatively simple. zipfill, zipcut, and zip make sense to me just by their names. zip(short, take(long, short.size())) makes me think about it. Even just having zipcut be a wrapper over that would make me happy. Not to say anything about conditions; I know nothing about them. _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
