(take n ch)
(take n ch buf-or-n)
Returns a channel that will return, at most, n items from ch. After n items
have been returned, or ch has been closed, the return chanel will close.
The output channel is unbuffered by default, unless buf-or-n is given.
Source
(defn
take
"Returns a channel that will return, at most, n items from ch. After n items\n have been returned, or ch has been closed, the return chanel will close.\n\n The output channel is unbuffered by default, unless buf-or-n is given."
([n ch] (take n ch nil))
([n ch buf-or-n]
(let
[out (chan buf-or-n)]
(go
(loop
[x 0]
(when
(< x n)
(let
[v (<! ch)]
(when (not (nil? v)) (>! out v) (recur (inc x))))))
(close! out))
out)))