← SPL reference

stream (lib/stream.py)

Pull-based synchronous “streams”: lazy chains terminated by stream.fold or stream.subscribe. There are no Promises/Futures/async in SPL—everything runs inside the interpreter on the caller’s stack.

Load extensionless (reqFileExtension = False): use stream;.

Algorithm & semantics

Example

use stream;

list.createList([1, -2, 3], Nums);

functionDefine.pos(v):
    return.number(test.isGreater(v, 0));
end;
functionDefine.dbl(v):
    return.number(math.multiply(v, 2));
end;
functionDefine.accumSum(acc, x):
    return.number(math.add(acc, x));
end;

s.setVar(stream.from_list(Nums));

s.setVar(stream.filter(s, function.ref(pos)));

s.setVar(stream.map(s, function.ref(dbl)));

t.setVar(stream.take(s, 5));

Tot.setVar(stream.fold(t, 0, function.ref(accumSum)));

print.number(Tot);

Implementation reference: someProgrammingLanguage/lib/stream.py.