Stream (abstract data type)

Last updated

In type theory and functional programming, a stream is a potentially infinite analog of a list, given by the coinductive definition: [1] [2]

dataStreamα=Nil|Consα(Streamα)

Generating and computing with streams requires lazy evaluation, either implicitly in a lazily evaluated language or by creating and forcing thunks in an eager language. In total languages they must be defined as codata and can be iterated over using (guarded) corecursion.

UML package diagram of the stream hierarchy in .NET UML dotnet streams.svg
UML package diagram of the stream hierarchy in .NET

Java provides the Stream interface under the java.util.stream namespace.

JavaScript provides the ReadableStream, WritableStream and TransformStream interfaces. [3]

Python have the StreamReader and StreamWriter classes in the asyncio module. [4]

.NET provides the abstract class Stream [5] which is implemented by classes such as FileStream and MemoryStream. [6]

In Rust a struct can implement the Read trait. [7] There is also the Cursor struct wraps an in-memory buffer. [8]

See also

Related Research Articles

<span class="mw-page-title-main">Serialization</span> Conversion process for computer data

In computing, serialization is the process of translating a data structure or object state into a format that can be stored or transmitted and reconstructed later. When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward. Serialization of objects does not include any of their associated methods with which they were previously linked.

UTF-8 is a character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode Transformation Format – 8-bit. Almost every webpage is stored in UTF-8.

In object-oriented programming, an interface or protocol type is a data type that acts as an abstraction of a class. It describes a set of method signatures, the implementations of which may be provided by multiple classes that are otherwise not necessarily related to each other. A class which provides the methods listed in a protocol is said to adopt the protocol, or to implement the interface.

In object-oriented (OO) and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.

In software systems, encapsulation refers to the bundling of data with the mechanisms or methods that operate on the data. It may also refer to the limiting of direct access to some of that data, such as an object's components. Essentially, encapsulation prevents external code from being concerned with the internal workings of an object.

Programming languages can be grouped by the number and types of paradigms supported.

In object-oriented programming such as is often used in C++ and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method that is dispatched dynamically. Virtual functions are an important part of (runtime) polymorphism in object-oriented programming (OOP). They allow for the execution of target functions that were not precisely identified at compile time.

In computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator.

In computing, vectored I/O, also known as scatter/gather I/O, is a method of input and output by which a single procedure call sequentially reads data from multiple buffers and writes it to a single data stream (gather), or reads data from a data stream and writes it to multiple buffers (scatter), as defined in a vector of buffers. Scatter/gather refers to the process of gathering data from, or scattering data into, the given set of buffers. Vectored I/O can operate synchronously or asynchronously. The main reasons for using vectored I/O are efficiency and convenience.

In computing, a stack trace is a report of the active stack frames at a certain point in time during the execution of a program. When a program is run, memory is often dynamically allocated in two places: the stack and the heap. Memory is continuously allocated on a stack but not on a heap, thus reflective of their names. Stack also refers to a programming construct, thus to differentiate it, this stack is referred to as the program's function call stack. Technically, once a block of memory has been allocated on the stack, it cannot be easily removed as there can be other blocks of memory that were allocated before it. Each time a function is called in a program, a block of memory called an activation record is allocated on top of the call stack. Generally, the activation record stores the function's arguments and local variables. What exactly it contains and how it's laid out is determined by the calling convention.

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

In computer science, futures, promises, delays, and deferreds are constructs used for synchronizing program execution in some concurrent programming languages. Each is an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is not yet complete.

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into a binary dynamic-link library.

In computer programming, a collection is an abstract data type that is a grouping of items that can be used in a polymorphic way.

<span class="mw-page-title-main">Rust (programming language)</span> General-purpose programming language

Rust is a general-purpose programming language emphasizing performance, type safety, and concurrency. It enforces memory safety, meaning that all references point to valid memory. It does so without a traditional garbage collector; instead, memory safety errors and data races are prevented by the "borrow checker", which tracks the object lifetime of references at compile time.

Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. It is implemented in C++ and officially supports development in C++, Rust/WinRT, Python/WinRT, JavaScript-TypeScript, and the managed code languages C# and Visual Basic (.NET) (VB.NET).

<span class="mw-page-title-main">WebAssembly</span> Assembly language and bytecode for web browsers

WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment.

<span class="mw-page-title-main">Zig (programming language)</span> General-purpose programming language

Zig is an imperative, general-purpose, statically typed, compiled system programming language designed by Andrew Kelley. It is free and open-source software, released under an MIT License.

This article compares the syntax for defining and instantiating an algebraic data type (ADT), sometimes also referred to as a tagged union, in various programming languages.

<span class="mw-page-title-main">Strongly typed identifier</span>

A strongly typed identifier is user-defined data type which serves as an identifier or key that is strongly typed. This is a solution to the "primitive obsession" code smell as mentioned by Martin Fowler. The data type should preferably be immutable if possible. It is common for implementations to handle equality testing, serialization and model binding.

References

  1. Yamagiwa, Shinichi (2022), Katoh, Naoki; Higashikawa, Yuya; Ito, Hiro; Nagao, Atsuki (eds.), "Stream-Based Lossless Data Compression", Sublinear Computation Paradigm: Algorithmic Revolution in the Big Data Era, Singapore: Springer, pp. 391–410, doi: 10.1007/978-981-16-4095-7_16 , ISBN   978-981-16-4095-7
  2. Sangma, Jerry W.; Sarkar, Mekhla; Pal, Vipin; Agrawal, Amit; Yogita (2022-04-01). "Hierarchical clustering for multiple nominal data streams with evolving behaviour". Complex & Intelligent Systems. 8 (2): 1737–1761. doi: 10.1007/s40747-021-00634-0 . ISSN   2198-6053.
  3. "Streams API - Web APIs | MDN". developer.mozilla.org. 26 July 2024. Retrieved 28 January 2025.
  4. "Streams". Python documentation. Retrieved 17 December 2024.
  5. "Stream Class (System.IO)". learn.microsoft.com. Microsoft. Retrieved 17 December 2024.
  6. "File and Stream I/O - .NET". learn.microsoft.com. Microsoft. 15 September 2021. Retrieved 17 December 2024.
  7. "Read in std::io - Rust". doc.rust-lang.org. Retrieved 28 January 2025.
  8. "Cursor in std::io - Rust". doc.rust-lang.org. Retrieved 28 January 2025.