diff --git a/src/observablecollection/src/Shared/ObservableList.lua b/src/observablecollection/src/Shared/ObservableList.lua index 3c033c457e..7a51b4b6d3 100644 --- a/src/observablecollection/src/Shared/ObservableList.lua +++ b/src/observablecollection/src/Shared/ObservableList.lua @@ -63,6 +63,27 @@ function ObservableList.new() return self end +--[=[ + Constructs an ObservableList populated via an observable of Brios + @param observable Observable> + @return ObservableList +]=] +function ObservableList.fromObservableBrio(observable) + local list = ObservableList.new() + + list._maid:GiveTask(observable:Subscribe(function(value) + assert(Brio.isBrio(value), "Observable must emit brio") + + if value:IsDead() then + return + end + + value:ToMaid():GiveTask(list:Add(value:GetValue())) + end)) + + return list +end + --[=[ Returns whether the value is an observable list @param value any diff --git a/src/observablecollection/src/Shared/ObservableSet.lua b/src/observablecollection/src/Shared/ObservableSet.lua index 227bc25236..15534910b8 100644 --- a/src/observablecollection/src/Shared/ObservableSet.lua +++ b/src/observablecollection/src/Shared/ObservableSet.lua @@ -56,6 +56,27 @@ function ObservableSet.new() return self end +--[=[ + Constructs an ObservableSet populated via an observable of Brios + @param observable Observable> + @return ObservableSet +]=] +function ObservableSet.fromObservableBrio(observable) + local set = ObservableSet.new() + + set._maid:GiveTask(observable:Subscribe(function(value) + assert(Brio.isBrio(value), "Observable must emit brio") + + if value:IsDead() then + return + end + + value:ToMaid():GiveTask(set:Add(value:GetValue())) + end)) + + return set +end + --[=[ Returns whether the value is an observable set @param value any