add vide.mutate()

This commit is contained in:
ewd3v 2024-08-31 21:03:00 +02:00
parent 82debeeffe
commit 33a38d75c4
No known key found for this signature in database
GPG key ID: 18FF74D0F35B288C
2 changed files with 17 additions and 0 deletions

View file

@ -16,6 +16,7 @@ local cleanup = require(script.cleanup)
local untrack = require(script.untrack)
local read = require(script.read)
local batch = require(script.batch)
local mutate = require(script.mutate)
local switch = require(script.switch)
local show = require(script.show)
local indexes, values = require(script.maps)()
@ -63,6 +64,7 @@ local vide = {
untrack = untrack,
read = read,
batch = batch,
mutate = mutate,
-- animations
spring = spring,

15
src/mutate.luau Normal file
View file

@ -0,0 +1,15 @@
if not game then script = require "test/relative-string" end
local untrack = require(script.Parent.untrack)
local function mutate<T>(source: () -> T, mutator: (T) -> any?)
local value = untrack(source)
local packed = table.pack(mutator(value))
if packed.n > 0 then
return source(unpack(packed, 1, packed.n))
end
source(value)
end
return mutate