Skip to content

Commit

Permalink
Merge pull request #248 from vito/add-take-all
Browse files Browse the repository at this point in the history
add `(take-all)` for reading all values from a pipe source
  • Loading branch information
vito authored Sep 11, 2022
2 parents e9f7e2b + a442a9c commit 0ee50a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 173 deletions.
5 changes: 5 additions & 0 deletions pkg/bass/ground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,11 @@ func TestGroundPipes(t *testing.T) {
Bass: "(take 2 (list->source [1 2 3]))",
Result: bass.NewList(bass.Int(1), bass.Int(2)),
},
{
Name: "take-all",
Bass: "(take-all (list->source [1 2 3]))",
Result: bass.NewList(bass.Int(1), bass.Int(2), bass.Int(3)),
},
{
Name: "across",
Bass: "(next (across (list->source [0 2 4]) (list->source [1 3 5])))",
Expand Down
9 changes: 5 additions & 4 deletions pkg/runtimes/testdata/addrs.bass
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(defn http-server [index]
(from (linux/nixery.dev/simple-http-server)
(-> ($ simple-http-server -i)
(from (linux/alpine)
($ apk add python3)
(-> ($ python3 -m http.server)
(with-mount (mkfile ./index.html index) ./index.html)
(with-port :http 8000))))

(let [srv (http-server "hello, world!")]
(-> ($ curl -s (addr srv :http "http://$host:$port"))
(with-image (linux/nixery.dev/curl))
(-> ($ wget -O- (addr srv :http "http://$host:$port"))
(with-image (linux/alpine))
(read :raw)
next
dump))
170 changes: 1 addition & 169 deletions pkg/runtimes/testdata/bass.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ memos: {
symbol: "digest"
value: {
string: {
value: "sha256:7580ece7963bfa863801466c0a488f11c86f85d9988051a9f9c68cb27f6b7872"
value: "sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad"
}
}
}
Expand Down Expand Up @@ -176,173 +176,5 @@ memos: {
}
}
}
results: {
input: {
array: {
values: {
object: {
bindings: {
symbol: "platform"
value: {
object: {
bindings: {
symbol: "os"
value: {
string: {
value: "linux"
}
}
}
}
}
}
bindings: {
symbol: "repository"
value: {
string: {
value: "nixery.dev/simple-http-server"
}
}
}
bindings: {
symbol: "tag"
value: {
string: {
value: "latest"
}
}
}
}
}
}
}
output: {
object: {
bindings: {
symbol: "repository"
value: {
string: {
value: "nixery.dev/simple-http-server"
}
}
}
bindings: {
symbol: "platform"
value: {
object: {
bindings: {
symbol: "os"
value: {
string: {
value: "linux"
}
}
}
}
}
}
bindings: {
symbol: "tag"
value: {
string: {
value: "latest"
}
}
}
bindings: {
symbol: "digest"
value: {
string: {
value: "sha256:13a32cf276567978ad829355e336174aa107f29e7cf078a25ec30ba1d1bc8d5d"
}
}
}
}
}
}
results: {
input: {
array: {
values: {
object: {
bindings: {
symbol: "platform"
value: {
object: {
bindings: {
symbol: "os"
value: {
string: {
value: "linux"
}
}
}
}
}
}
bindings: {
symbol: "repository"
value: {
string: {
value: "nixery.dev/curl"
}
}
}
bindings: {
symbol: "tag"
value: {
string: {
value: "latest"
}
}
}
}
}
}
}
output: {
object: {
bindings: {
symbol: "repository"
value: {
string: {
value: "nixery.dev/curl"
}
}
}
bindings: {
symbol: "platform"
value: {
object: {
bindings: {
symbol: "os"
value: {
string: {
value: "linux"
}
}
}
}
}
}
bindings: {
symbol: "tag"
value: {
string: {
value: "latest"
}
}
}
bindings: {
symbol: "digest"
value: {
string: {
value: "sha256:ea6ad85d3dfbf10668b325aa4382eea4859df41cdd160d7204bd9200a698b24d"
}
}
}
}
}
}
}
}
9 changes: 9 additions & 0 deletions std/streams.bass
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@
(if (<= n 0)
[]
(cons (next source) (take (- n 1) source))))

; reads all values from the source into a list
;
; => (take-all (list->source [1 2 3]))
(defn take-all [source]
(let [val (next source _)]
(if (ignore? val)
[]
(cons val (take-all source)))))

0 comments on commit 0ee50a8

Please sign in to comment.