<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: group-by code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 22:04:27 GMT</pubDate>
    <description>DZone Snippets: group-by code</description>
    <item>
      <title>group-by function</title>
      <link>http://snippets.dzone.com/posts/show/1124</link>
      <description>&lt;code&gt;&lt;br /&gt;    group-by: func [  &lt;br /&gt;        {Returns a block of blocks+sub-blocks with items partitioned by&lt;br /&gt;        matching index elements in each sub-block.}&lt;br /&gt;        block  [any-block!] "A block of blocks"&lt;br /&gt;        index  [integer!] "Index of sub-block value to compare, for grouping."&lt;br /&gt;        /local keys&lt;br /&gt;    ][&lt;br /&gt;        result: copy []&lt;br /&gt;        foreach item block [&lt;br /&gt;            if not find/skip result item/:index 2 [&lt;br /&gt;                append result reduce [item/:index copy []]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;        foreach item block [&lt;br /&gt;            append/only select result item/:index item&lt;br /&gt;        ]&lt;br /&gt;        result&lt;br /&gt;    ]&lt;br /&gt;    ;group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5]] 1&lt;br /&gt;    ;group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5] [c 2 4]] 2&lt;br /&gt;    ;group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5] [c 2 4]] 3&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jan 2006 06:17:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1124</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
