Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active January 31, 2026 06:05
Show Gist options
  • Select an option

  • Save sogaiu/2d0977e837956efbcc779519689396c4 to your computer and use it in GitHub Desktop.

Select an option

Save sogaiu/2d0977e837956efbcc779519689396c4 to your computer and use it in GitHub Desktop.
janet tidbits
# `(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