Lua-Collections
Lua-Collections copied to clipboard
Method to return one of each unique items in the collection
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' }
}
]]
Hi, and thanks for this awesome library! In many other collections libs, this method is called distinct. And IMO the library is really lacking it :)