-
Notifications
You must be signed in to change notification settings - Fork 5
With and without
We've already seen the use of the with operator to construct new struct values, e.g. Person with name::"Joseph", age::22, where Person is the name of a type and name::"Joseph", age::22 is a tuple of pairs.
We use the same with operator and the same syntax to copy and modify existing values.
This is important because in Pipefish, all values are immutable. You cannot change the nth item of a list or struct, or add a key to a map, or change the value associated with an existing key. Instead, you can ask Pipefish for a copy of the list/map/struct with an element or elements changed. Let's demonstrate this in the TUI, first running a little script to declare some data for us to copy-and-modify.
The without operator for maps returns a copy of the map with the given key or keys removed.
No error is returned if the key is not in the map: Pipefish consistently treats deletion as an idempotent operation.
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.