Functions

'map
I

Applies a function to each member of a stream and returns a stream of the results.

close
I

Closes a stream.

filter
I

Selects the members from a stream for which a function returns true.

forEach
I

Applies a function to each member of a stream.

iterator
I

Returns an iterator over a stream.

next
I

Returns the next element in the stream wrapped in a record or () if the stream ends.

reduce
I

Combines the members of a stream using a combining function.

'map

function 'map(stream<Type, CompletionType> stm,  function(Type) returns (Type1) func) returns stream<Type1, CompletionType>
Isolated Function

Applies a function to each member of a stream and returns a stream of the results.

Parameters

  • func function(Type) returns (Type1)
  • a function to apply to each member

Return Type

(stream<Type1, CompletionType>)

new stream containing result of applying function func to each member of parameter stm in order

close

function close(stream<Type, CompletionType> stm) returns CompletionType?
Isolated Function

Closes a stream.

This releases any system resources being used by the stream. Closing a stream that has already been closed has no efffect and returns ().

Parameters

Return Type

(CompletionType?)

() if the close completed successfully, otherwise an error

filter

function filter(stream<Type, CompletionType> stm,  function(Type) returns (boolean) func) returns stream<Type, CompletionType>
Isolated Function

Selects the members from a stream for which a function returns true.

Parameters

  • func function(Type) returns (boolean)
  • a predicate to apply to each member to test whether it should be selected

Return Type

(stream<Type, CompletionType>)

new stream only containing members of parameter stm for which function func evaluates to true

forEach

function forEach(stream<Type, CompletionType> stm,  function(Type) returns (() ) func) returns CompletionType
Isolated Function

Applies a function to each member of a stream.

The function func is applied to each member of parameter stm stream in order.

Parameters

  • func function(Type) returns (() )
  • a function to apply to each member

Return Type

(CompletionType)

() if the close completed successfully, otherwise an error

iterator

function iterator(stream<Type, CompletionType> stm) returns object {
    public isolated function next() returns record {|
        Type value;
    |}|CompletionType;
}
Isolated Function

Returns an iterator over a stream.

Parameters

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.

function next(stream<Type, CompletionType> strm) returns record {| value Type |} | CompletionType
Isolated Function

Returns the next element in the stream wrapped in a record or () if the stream ends.

Parameters

Return Type

(record {| value Type |} | CompletionType)

If the stream has elements, return the element wrapped in a record with single field called value, otherwise returns ()

reduce

function reduce(stream<Type, ErrorType?> stm,  function(Type1, Type) returns (Type1) func, Type1 initial) returns Type1 | ErrorType
Isolated Function

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 Type1
  • initial value for the first argument of combining function func

Return Type

(Type1 | ErrorType)

result of combining the members of parameter stm using function func