From bf4218ce255d4e266cf249bdad43a3fc95f5e6d6 Mon Sep 17 00:00:00 2001 From: KreatorKols Date: Thu, 23 Apr 2026 12:34:27 -0500 Subject: [PATCH 1/3] feat: added contains check to observable lists --- .../src/Shared/ObservableList.lua | 15 +++++++++++++++ .../src/Shared/ObservableList.spec.lua | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/observablecollection/src/Shared/ObservableList.lua b/src/observablecollection/src/Shared/ObservableList.lua index a5e932fecd..3acc92c0ca 100644 --- a/src/observablecollection/src/Shared/ObservableList.lua +++ b/src/observablecollection/src/Shared/ObservableList.lua @@ -323,6 +323,21 @@ function ObservableList.Get(self: ObservableList, index: number): T? return self._contents[key] end +--[=[ + Checks if the list contains a value + @param value T + @return boolean +]=] +function ObservableList.Contains(self: ObservableList, value: T): boolean + for _, item in self._contents do + if item == value then + return true + end + end + + return false +end + --[=[ Adds the item to the list at the specified index @param item T diff --git a/src/observablecollection/src/Shared/ObservableList.spec.lua b/src/observablecollection/src/Shared/ObservableList.spec.lua index 40b2952807..7b63bac519 100644 --- a/src/observablecollection/src/Shared/ObservableList.spec.lua +++ b/src/observablecollection/src/Shared/ObservableList.spec.lua @@ -35,6 +35,15 @@ describe("ObservableList.new()", function() expect(observableList:Get(-2)).toEqual(nil) end) + it("should allow negative queries", function() + expect(observableList:Get(-1)).toEqual("a") + expect(observableList:Get(-2)).toEqual(nil) + end) + + it("should check if the list contains a value", function() + expect(observableList:Contains("a")).toEqual(true) + end) + it("should allow false as a value", function() expect(observableList:Get(2)).toEqual(nil) observableList:Add(false) From a6d717c3101068ea0335087ad16cfe3700ebdd24 Mon Sep 17 00:00:00 2001 From: KreatorKols Date: Thu, 23 Apr 2026 12:35:47 -0500 Subject: [PATCH 2/3] fix: removed repeated check --- src/observablecollection/src/Shared/ObservableList.spec.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/observablecollection/src/Shared/ObservableList.spec.lua b/src/observablecollection/src/Shared/ObservableList.spec.lua index 7b63bac519..b1130259f0 100644 --- a/src/observablecollection/src/Shared/ObservableList.spec.lua +++ b/src/observablecollection/src/Shared/ObservableList.spec.lua @@ -35,11 +35,6 @@ describe("ObservableList.new()", function() expect(observableList:Get(-2)).toEqual(nil) end) - it("should allow negative queries", function() - expect(observableList:Get(-1)).toEqual("a") - expect(observableList:Get(-2)).toEqual(nil) - end) - it("should check if the list contains a value", function() expect(observableList:Contains("a")).toEqual(true) end) From d2f7a25ca4ea814ce3c922ef92c906a26f6ff9c4 Mon Sep 17 00:00:00 2001 From: KreatorKols Date: Fri, 24 Apr 2026 14:31:21 -0500 Subject: [PATCH 3/3] docs: added warning to contains check --- src/observablecollection/src/Shared/ObservableList.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/observablecollection/src/Shared/ObservableList.lua b/src/observablecollection/src/Shared/ObservableList.lua index 3acc92c0ca..beff27bcdf 100644 --- a/src/observablecollection/src/Shared/ObservableList.lua +++ b/src/observablecollection/src/Shared/ObservableList.lua @@ -325,6 +325,11 @@ end --[=[ Checks if the list contains a value + + :::warning + This can scan the whole list each call; cost is linear in the number of entries. + ::: + @param value T @return boolean ]=]