lang.stream
ballerina/lang.stream
Module overview
The lang.stream
module corresponds to the stream
basic type.
Functions
'map
function 'map(stream<any|error, error|()> stm, function(any|error) returns (any|error)
func) returns stream<any|error, error|()>
Applies a function to each member of a stream and returns a stream of the results.
Parameters
close
Closes a stream.
This releases any system resources being used by the stream.
Closing a stream that has already been closed has no effect and returns ()
.
Return Type
- error|()? - () if the close completed successfully, otherwise an error
filter
function filter(stream<any|error, error|()> stm, function(any|error) returns (boolean)
func) returns stream<any|error, error|()>
Selects the members from a stream for which a function returns true.
Parameters
forEach
function forEach(stream<any|error, error|()> stm, function(any|error) returns (() )
func) returns error|()
Applies a function to each member of a stream.
The parameter func
is applied to each member of parameter stm
stream in order.
Parameters
- func
function(any|error) returns (() )
- a function to apply to each member
Return Type
- error|() - () if the close completed successfully, otherwise an error
iterator
function iterator(stream<any|error, error|()> stm) returns object {
public isolated function next() returns record {|
Type value;
|}|CompletionType;
}
Returns an iterator over a stream.
Return Type
- object {
public isolated function next() returns record {|
Type value;
|}|CompletionType;
} - a new iterator object that will iterate over the members of parameter
stm
.
next
Returns the next element in the stream wrapped in a record or () if the stream ends.
reduce
function reduce(stream<any|error, ErrorType?> stm, function(any|error, any|error) returns (any|error)
func, any|error initial) returns any|error|ErrorType
Combines the members of a stream using a combining function.
The combining function takes the combined value so far and a member of the stream, and returns a new combined value.
Parameters
- initial any|error - initial value for the first argument of combining parameter
func
Return Type
- any|error|ErrorType - result of combining the members of parameter
stm
using parameterfunc
Types
lang.stream: Type
A type parameter that is a subtype of any|error
.
Has the special semantic that when used in a declaration
all uses in the declaration must refer to same type.
lang.stream: Type1
A type parameter that is a subtype of any|error
.
Has the special semantic that when used in a declaration
all uses in the declaration must refer to same type.
Errors
lang.stream: ErrorType
A type parameter that is a subtype of error
.
Has the special semantic that when used in a declaration
all uses in the declaration must refer to same type.