Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

GROUP - group like elements in a block (See related posts)

    group: func [
        {Returns a block of sub-blocks with items partitioned by value.}
        block  [any-block!]
        /local result
    ][
        result: copy []
        ; First, build up a list of keys, with a place for values
        ; to go with each key.
        foreach item block [
            if not find/only/skip result item 2 [
                repend result [item copy []]
            ]
        ]
        ; Add items to the block associated with each key.
        foreach item block [append/only select result item item]
        result
    ]

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts