Nice TWiki > Dev > StandardLibrary (r1.14 vs. r1.15) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
 <<O>>  Difference Topic StandardLibrary (r1.15 - 02 Feb 2004 - BrynKeller)
Added:
>
>

These days, if you want this sort of thing, you just use the generator library in nice.functional. If you want to break out of a map/filter/etc. you just call stop() and that's equivalent to breaking. So:

import nice.functional;

let foo = naturals().filter(
              int i => {if (i == 53) { stop(); } return odd(i);
          ).map(int i => i.toString);

gives you a generator which starts with all the naturals, filtered down to only the odd ones, converted to strings. Except the method passed to filter calls stop() when it hits i == 53, so the whole chain ends at that point. It turned out to be a lot simpler than rewriting the entire collection hierarchy and so on.

-- BrynKeller - 02 Feb 2004


Topic StandardLibrary . { View | Diffs | r1.16 | > | r1.15 | > | r1.14 | More }
Revision r1.14 - 08 Aug 2003 - 13:43 GMT - ArjanB
Revision r1.15 - 02 Feb 2004 - 23:21 GMT - BrynKeller
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.