/* ----------------------------------------------------------------------------- Copyright 2019-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] // A sink for writing data. // // Params: // - #x: The value type to be written. @value interface Writer<#x|> { write (#x) -> () } // A sink that can be flushed. // // Params: // - #x: The value type to be written. @value interface BufferedWriter<#x|> { refines Writer<#x> flush () -> () } // A sink that might perform a partial write. // // Params: // - #x: The value type to be written. @value interface BlockWriter<#x|> { // Write the data and return the size of what was written. writeBlock (#x) -> (Int) } // A lazy output stream that delays writing. // // Params: // - #x: The value type to be written. concrete LazyStream<#x> { refines Append<#x> // Create a new stream. @type new () -> (LazyStream<#x>) // Write the data to the BufferedWriter. (Do not mutate the stream.) @value writeTo (BufferedWriter<#x>) -> () } // Simple output destinations. concrete SimpleOutput { refines BufferedWriter // Returns a BufferedWriter for standard output. @type stdout () -> (BufferedWriter) // Returns a BufferedWriter for standard error. @type stderr () -> (BufferedWriter) // Returns a BufferedWriter that crashes with the output as the error message. @type error () -> (BufferedWriter) }