aboutsummaryrefslogtreecommitdiff
path: root/notes/pipes_iteration_append_etc.txt
blob: 1b927feed22c28a38d0584dbe9f7d6f613c42e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

Efficient pipes would be nice. This can work simply by chunking the input
and output.

That technique can be used for iterators, ranges, etc.
(Similar to how you can do `seq 100 | while read n` in shell.)

Functions like these should be pipe-able:

    # Simple function taking a value and returning a value
    func abs n -> np
    # Function taking an argument in addition to the "value"
    func min a b -> x
    # Function returning a list/sequence
    func range low high -> seq
    # Function consuming values
    func Stream.write s
    # Function producing values
    func rand_int low high -> n

Should string appending be pipe-able somehow?

    for String chunk in chunks {
        s += "chunk: " + chunk + "\n"
    }

Maybe the += operator could have a piped variant as well?

* In most cases it would probably be called for each iteration (no chunking),
  but it would know that more values are coming.
* Also, `x += a + b + c` should be turned into `x+=a; x+=b; x+=c;`,
  at least if x/a/b/c all have the same type.
* Need to take into account if the object is used (e.g. printed) during
  the loop.