/* ----------------------------------------------------------------------------- Copyright 2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] // Container with stack semantics. // // Params: // - #x: The value type to stack. @value interface Stack<#x> { refines Container // Pushes a new value and returns self. push (#x) -> (#self) // Pops the top value. Crashes if empty. (Check size() before calling.) pop () -> (#x) } // Writing to key-value storage. // // Params: // - #k: The key type. // - #v: The value type. @value interface KVWriter<#k,#v|> { // Sets or replaces the value associated with the key and returns self. set (#k,#v) -> (#self) // Removes the value associated with the key if present and returns self. remove (#k) -> (#self) } // Reading from key-value storage. // // Params: // - #k: The key type. // - #v: The value type. @value interface KVReader<#k|#v> { // Returns the value associated with the key if present. get (#k) -> (optional #v) } // Writing to a set of values. // // Params: // - #k: The type stored in the set. @value interface SetWriter<#k|> { add (#k) -> (#self) remove (#k) -> (#self) } // Checking a set of values. // // Params: // - #k: The type stored in the set. @value interface SetReader<#k|> { member (#k) -> (Bool) } // Factory for creating a new key-value pair. @type interface KVFactory<#k,#v|> { // Create a new pair from the provided key and value. newNode (#k,#v) -> (#self) } // A single key-value pair from a KVReader. @value interface KeyValue<|#k,#v> { // Get the key. // // Notes: // - Calling mutating functions on the key could invalidate the structure of // the KVReader. getKey () -> (#k) // Get the value. getValue () -> (#v) }