Skip to content

Method to return one of each unique items in the collection #2

Description

@imliam

It would be beneficial to have a method that returns only one of each item in the collection that matches a particular value.

collect({1, 1, 2, 2, 3, 4, 2}):methodName():all()
-- {1, 2, 3, 4}

collect({
    { animal = 'Cat', name = 'Bob' },
    { animal = 'Dog', name = 'Tim' },
    { animal = 'Cat', name = 'Beverly' }
}):methodName('animal'):all()
--[[
    {
        { animal = 'Cat', name = 'Bob' },
        { animal = 'Dog', name = 'Tim' }
    }
]]

collect({
    { animal = 'Cat', name = 'Bob' },
    { animal = 'Dog', name = 'Tim' },
    { animal = 'Cat', name = 'Beverly' }
}):methodName(function(key, value)
    return value:sub(1,1)
end):all()
--[[
    {
        { animal = 'Cat', name = 'Bob' },
        { animal = 'Dog', name = 'Tim' }
    }
]]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions