This thread proposes changes relating primarily to syntactic sugar. Practically speaking, I’m not sure of how impactful this is. Probably something in the ballpark of Roblox adding
Right now, all methods for tables that come out of the box (minus foreach and its siblings) accept direct values. This is inclusive of Roblox’s own
table.find. Over my time working with Luau and getting used to other languages in my spare time, I’ve found that having methods for tables that accept predicates is something really awesome when it comes to other languages. Having these sorts of things for arrays or other enumerable/iterable objects is overall really awesome and shortens code quite a bit. An immediate side effect of this implementation is that Luau is not going to support lambda expressions, and when it comes to methods accepting predicates, lambda expressions go together with predicates like cake and ice cream. So it may be a bit strange having to use anonymous functions in their place for some developers. No matter –
To work around this inconvenience, I implement my own extension module, which enables me to write code such as
local objects = table.where(workspace.Something:GetChildren(), function(obj) return obj:IsA("BasePart") and obj.Name == "Thingy" end)
(which would return all instances in
workspace.Something that cause that function to return
A number of other similar predicate-accepting methods exist in my module, to name them:
table.contains– Returns whether or not the table has at least one element that satisfies a predicate.
table.where– Returns a new array containing all elements that satisfy a predicate.
table.first– Returns the first element that satisfies a predicate.
table.count– Returns the amount of elements that satisfy a predicate.
table.removeWhere– Removes all elements from the given array that satisfy a predicate.
table.transform– Modifies every value in the array with the given modification function, which returns a replacement value, or nil to remove that item.
All of these function on arrays only, and do not support iterating over non-linear integer keys.
In my opinion, the most important of these are
first. Every other method in that list could be created from these, which makes them the stars of this feature request.