https://github.com/markmandel/while-let
Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test.
https://github.com/markmandel/while-let
Last synced: about 1 year ago
JSON representation
Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test.
- Host: GitHub
- URL: https://github.com/markmandel/while-let
- Owner: markmandel
- License: epl-1.0
- Created: 2014-01-08T02:48:07.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2021-05-22T14:29:29.000Z (about 5 years ago)
- Last Synced: 2025-04-10T06:32:34.107Z (about 1 year ago)
- Language: Clojure
- Size: 169 KB
- Stars: 20
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# while-let
Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test.
I've found this particularly useful with [core.async](https://github.com/clojure/core.async), where you want to loop
until a channel is closed (and it returns nil).
## Installation
In your project.clj add:

## Usage
```
(while-let bindings & body)
```
### Simple example
Pop each item off the front of a vector and print it out.
```clojure
(let [data (atom [1 2 3 4 5])]
(while-let [item (first @data)]
(println "item: " item)
(swap! data rest)))
```
### Core.async example:
Take from a channel until it gets closed (a closed channel will return `nil`), or the channel returns `false`
```clojure
(go (while-let [data (