~subsetpark/janet-streams

Fiber-based streams for Janet.
0e9c05f0 — Zach Smith 10 months ago
mapcat
b361d2c3 — Zach Smith 10 months ago
Remove unused element
edc05df7 — Zach Smith 10 months ago
add License

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~subsetpark/janet-streams
read/write
git@git.sr.ht:~subsetpark/janet-streams

You can also use your local clone with git send-email.

#streams API

#Streams for Janet

A stream is an iterable data structure which yields individual values whenever called, potentially until its internal values are exhausted, at which point it's considered dead.

This operation makes them very useful for:

  • Asynchronous behaviour
  • Memory-sensitive applications, where it's not necessary to keep an entire sequence in memory at once
  • Infinite sequences

#streams

concat, cycle, drop, drop-until, drop-while, filter, from-iterable, map, range, run, take, take-until, take-while, to-array

#concat

function | source

(concat & xs)

Concatenate one or more streams or iterables into a single stream.

#cycle

function | source

(cycle ds)

Repeatedly yield the elements of ds, looping back to the beginning when finished.

#drop

function | source

(drop n ds)

Drop n elements from ds.

#drop-until

function | source

(drop-until p ds)

Drop elements from ds until p is true.

#drop-while

function | source

(drop-while p ds)

Drop elements from ds while p is true.

#filter

function | source

(filter p ds)

Create a stream that filters ds with p.

#from-iterable

function | source

(from-iterable ds)

Create a new stream around any iterable data structure.

#map

function | source

(map f ds)

Create a stream that maps f over ds.

#range

function | source

(range from to)

Create a lazy range.

#run

function | source

(run s)

Evaluate s for side effects.

NB: this will create an infinite loop if s is an infinite stream!

#take

function | source

(take n ds)

Take n elements from iterable ds.

#take-until

function | source

(take-until p ds)

Return elements from ds until p is true.

#take-while

function | source

(take-while p ds)

Return elements from ds while p is true.

#to-array

function | source

(to-array s)

Consume s into a new array.

NB: this will create an infinite loop if s is an infinite stream!