diff --git a/lang/lib/stream.bal b/lang/lib/stream.bal
index c9f5c3d0..e27eefa7 100644
--- a/lang/lib/stream.bal
+++ b/lang/lib/stream.bal
@@ -27,6 +27,13 @@ type Type any|error;
@typeParam
type ErrorType error;
+# 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.
+# This represents the result type of an iterator.
+@typeParam
+type ResultType error?;
+
# 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.
@@ -37,10 +44,10 @@ type Type1 any|error;
#
# + stm - the stream
# + return - a new iterator object that will iterate over the members of `stm`.
-public function iterator(stream
A stream is an object-like value that can generate a sequence of values. The
-generation of the sequence may either be successful or may fail at some point
-with an error. A stream belongs to type
A stream supports two primitive operations: a next operation and a close
operation. The next operation has the same semantics as the next method on the
Iterator abstract object type. The close operation informs the stream that there
will be no more next operations and thus allows the stream to release resources
-used by the stream; the close operation on a
-The normal implementation of a
The stream module of the lang library provides
@@ -1991,8 +1989,8 @@ 5. Values, types and variables
Iteration sequence
Type descriptor
Type of values in iteration sequence
-Typeof result
+Type of result
string
@@ -631,9 +631,9 @@ 5. Values, types and variables
@@ -1958,31 +1958,29 @@ stream
items
-
+stream<T,E>
stream<T,R>
-T
+E|()
R
[Preview] Streams
stream<T,E>
if the
-values in the generated sequence all belong to T and if any error on failure
-belongs to E. A stream belongs to type stream<T>
if the
-values in the generated sequence all belong to T and the generation of the
-sequence never fails. Thus stream<T> is equivalent to
-stream<T,never>
, where never
is the type to
-which no values belong. A value belongs to a type stream
(without
-the type-parameter) if it has basic type stream.
+generation of the sequence has a result value, which is either nil, indicating
+the sequence was generated successfully, or an error. A stream belongs to type
+stream<T,R>
if the values in the generated sequence all
+belong to T and if the result value belongs to R. The type
+stream<T>
is equivalent to stream<T,()>
. A
+value belongs to a type stream
(without the type-parameter) if it
+has basic type stream. A type stream<T,R>
where R does not
+include nil represents an unbounded stream.
stream<T,E>
may
-return an error of type E
.
+used by the stream; the close operation on a stream<T,R>
has
+a result of type R?
, where nil means that the close operation was
+successful.
stream<T,E>
is a wrapper
+The normal implementation of a stream<T,R>
is a wrapper
around an object belonging to abstract object type
-StreamImplementor<T,E?>
. The next and close operations on
-the stream delegate to the next and close methods on the StreamImplementor. Note
-that nil is implicitly included in the second type parameter of stream, but is
-explicit in the second parameter of StreamImplementor.
+StreamImplementor<T,R>
. The next and close operations on
+the stream delegate to the next and close methods on the StreamImplementor.
[Preview] Streams
A stream is iterable. The type of the values The type of the values in the
-iteration sequence of a value belonging stream<T,E>
is
-T
and the type of the iterations result is E?
. Calling
+iteration sequence of a value belonging stream<T,R>
is
+T
and the type of the iteration's result is R
. Calling
the next method on the iterator created for an iteration has the same effect as
performing the next operation on the stream. The stream does not keep a copy of
the sequence of values returned by the next operation. Any subsequent iteration
@@ -2242,8 +2240,8 @@
An object belongs to the abstract object type StreamImplementor<T,R> if it
belongs to Iterator<T,R> and also optionally has a method
-close()
with return value R. This is equivalent to belonging to the
-following type.
+close()
with return value R?
. This is equivalent to
+belonging to the following type.
StreamImplementor } | abstract object { public next() returns record {| T value; |}|R; - public close() returns R; + public close() returns R?; }