Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(map |($ {:a 7 :b 8 } ) [ keys values kvs pairs ])
# => @[ @[:a :b] @[7 8] @[:a 7 :b 8] @[(:a 7) (:b 8)] ]
(map |($ [4 5 6 ] ) [ keys values kvs pairs ])
# => @[ @[0 1 2] @[4 5 6] @[0 4 1 5 2 6] @[(0 4) (1 5) (2 6)] ]
(map |($ 'ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ :ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ "ab" ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(>= 4 2 )
# => true
# multiple values
(>= 4 4 3 2 1 1 )
# => true
# with array in apply call
(apply >= [4 4 3 2 1 1 ])
# => true
# with array in splice form
(>= ;[4 4 3 2 1 1 ])
# => true (map tuple ["a" "b" "c" "d" ] [1 2 3 4 ] "abcd" )
# => @[("a" 1 97) ("b" 2 98) ("c" 3 99) ("d" 4 100)] (map function? [ even? (fn []) |($ ) file/read -> ])
# => @[ true true true false true ]
(buffer/bit @"1" 0 )
# => true
(map dictionary? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false true true ]
(map struct? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false true false ]
(map table? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false false true ] (math/log (* math/e math/e )) # => 2
(math/log2 256 ) # => 8
(math/log10 1000 ) # => 3
(get-in {:a {:cc 2 } :b {:dd 3 }} [:a ] 42 ) # => {:cc 2}
(get-in {:a {:cc 2 } :b {:dd 3 }} [:a :cc ] 42 ) # => 2
(get-in {:a {:cc 2 } :b {:dd 3 }} [0 ] 42 ) # => 42
(get-in {:a {:cc 2 } :b {:dd 3 }} [:z ] 42 ) # => 42
# Due to: https://github.com/swlkr/janetdocs/issues/50
(defn parse-date
"Parses YYYY-MM-DD date format to time"
[date ]
(let [[year month day ] (map scan-number (string/split "-" date ))]
(os/mktime {:year year :month (dec month ) :month-day (dec day )})))
(print (parse-date "2021-01-01" )) # 1609459200
(print (os/strftime "%c" (parse-date "2021-01-01" ))) # Fri Jan 1 00:00:00 2021 (update-in @{:a 1 } [:a ] (fn [x ] (+ 1 x )))
# @{:a 2}
# Flatten single level of nested collections
(def foo [ [[1 2 ] [3 4 ]]
[[5 6 ] [7 8 ]] ])
(apply array/concat @[] foo ) # => @[(1 2) (3 4) (5 6) (7 8)] (string/slice "hello" ) # => "hello"
(string/slice "hello" 0 ) # => "hello"
(string/slice "hello" 1 ) # => "ello"
(string/slice "hello" 4 ) # => "o"
(string/slice "hello" 5 ) # => ""
(string/slice "hello" -1 ) # => ""
(string/slice "hello" -2 ) # => "o"
(string/slice "hello" -5 ) # => "ello"
(string/slice "hello" -6 ) # => "hello"
(string/slice "hello" 1 1 ) # => ""
(string/slice "hello" 1 2 ) # => "e"
(string/slice "hello" 1 5 ) # => "ello"
(string/slice "hello" -5 -4 ) # => "e"
(string/slice "hello" -6 -4 ) # => "he"
(string/slice "hello" 2 1 ) # => ""
(string/slice "hello" -1 -2 ) # => ""
[1 2 3] # => (1 2 3)
(tuple 1 2 3) # => (1 2 3)
(tuple (splice [1 2 3]) # => (1 2 3)
(tuple ;[1 2 3]) # => (1 2 3)
(peg/find-all ':d "Battery temperature: 40 °C" )
# => @[21 22] indices containing digits
# :d (range "09")
# peg grammars are contained in a table @{} (mutable) located in boot.janet source file.
# many terminals will truncate long data, use this if you need to see/copypaste it:
(defn full-print `Print a large DS without truncation` [ds ] (print (string/format "%m" ds )))