Skip to content

Instantly share code, notes, and snippets.

@christineponyl
Created October 17, 2019 23:26
Show Gist options
  • Save christineponyl/de69ab81f529f0b0cb06412bd3810939 to your computer and use it in GitHub Desktop.
Save christineponyl/de69ab81f529f0b0cb06412bd3810939 to your computer and use it in GitHub Desktop.
// how to send snapshot of values from mutable container field to another actor
use "itertools"
use mut = "collections"
use "collections/persistent"
actor Receiver
let env: Env
new create(env': Env) =>
env = env'
be print(li: List[I32] val) => // bc actor, parameters must be sendable
for item in li.values() do
env.out.print(item.string())
end
actor Main
let _data: mut.Map[USize, List[I32]] ref = mut.Map[USize, List[I32]](8)
let helper: Receiver
let env: Env
new create(env': Env) =>
env = env'
helper = Receiver(env)
helper.print(Lists[I32]([as I32: -2; -1; 0])) // test apparatus on val literal
go()
be go() =>
try
_data(1234) = Lists[I32]([1;2;3;4])
helper.print(_data(1234)?)
_data(5678) = Lists[I32]([5;6;7;8])
helper.print(_data(5678)?)
_data(1234) = _data(1234)?.map[I32]({(x) => x + 8}) // "update" existing entry in the Map (creates a new persistent list under the covers)
helper.print(_data(1234)?)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment