Last active
January 31, 2026 06:05
-
-
Save sogaiu/2d0977e837956efbcc779519689396c4 to your computer and use it in GitHub Desktop.
janet tidbits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # `(next x)` can be used as a synonym for `(not (empty? x))` | |
| # if `next` returns `nil`, the argument is empty. | |
| (next []) | |
| # => | |
| nil | |
| # if `next` returns non-nil, the argument is not empty. | |
| (next [:a :b]) | |
| # => | |
| 0 | |
| ######################################################################## | |
| # `(invert x)` can be used to create a "pseudo-set" | |
| # pass an indexed type to `invert` to get back a table | |
| (invert [:a :b]) | |
| # => | |
| @{:a 0 :b 1} | |
| ######################################################################## | |
| # `(os/stat p)` can be used to check if a path exists | |
| # with a second argument of `:mode`, gets an indication of what | |
| (os/stat "/" :mode) | |
| # => | |
| :directory | |
| # if `os/stat` returns `nil` for some path, that path has no associated file/dir/etc. | |
| (os/stat "non-existent") | |
| # => | |
| nil | |
| ######################################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment