Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(string/bytes "hello" ) # => (104 101 108 108 111) (get [4 5 6 ] -1 ) # => nil
(in [4 5 6 ] -1 42 ) # error
(get-in [4 5 6 ] [-1 ] 42 ) # => 42
(get {:a 1 } -1 ) # => nil
(in {:a 1 } -1 42 ) # => 42
(get-in {:a 1 } [-1 ] 42 ) # => 42 (update-in @{:a 1 } [:a ] (fn [x ] (+ 1 x )))
# @{:a 2}
(map nil? [nil 0 false [] ])
# => @[true false false false]
(seq [v :in (coro
(yield :hi )
(yield :bye ))]
v )
# => @[:hi :bye] (string "hello " "world" ) # => "hello world"
(os/execute
["python" "-c" "print('Hello Janet'" ])
:p (def [stdin-r stdin-w ] (os/pipe ))
(def [stdout-r stdout-w ] (os/pipe ))
# write the input that will be sent to sed
(:write stdin-w "hello world 1\nhello world 2" )
(:close stdin-w )
(os/execute
["sed" "s|world|janet|g" ]
:px
# the program reads from :in and writes to :out
{:in stdin-r :out stdout-w })
(:read stdout-r math/int32-max )
# => @"hello janet 1\nhello janet 2"
# feed two lines to sed, which replaces "world"
# with "janet", and read the modified results back (drop-until |(> $ 8 )
[1 1 2 3 4 5 8 13 21 ])
# => '(13 21)
(invert [(chr "y" ) (chr "o" )])
# => @{111 1 121 0} (math/round 1.1 ) # => 1
(map math/round [1.49 1.50 1.51 ]) # => @[1 2 2]
# janet 1.10.1
(all pos? [1 2 3 ]) # => true
(all pos? [1 2 3 -4 ]) # => false
(all pos? [1 2 3 0 ]) # => false
(all (partial string/has-prefix? "a" ) ["aa" "ab" ]) # => true
(all (partial string/has-prefix? "a" ) ["aa" "ab" "bb" ]) # => false
(all truthy? [1 2 ]) # => true
(all truthy? [1 2 3 ]) # => true
(all truthy? [1 2 nil 3 ]) # => false
(all truthy? [1 false 2 nil 3 ]) # => false
(all (fn [x ] x ) [1 2 ]) # => 2
(all (fn [x ] x ) [1 2 3 ]) # => 3
(all (fn [x ] x ) [1 2 nil 3 ]) # => nil
(all (fn [x ] x ) [1 false 2 nil 3 ]) # => false
(peg/find ':a "Battery temperature: 40 °C" )
# => 0 index of the first upper/lower case character
# :a (range "az" "AZ") (ev/spawn (os/sleep 1 ) (print "Hard work is done!" ))
# prints "Hard work is done!" after one second
# this is the easiest way to put some forms on the event loop
# but do not forget REPL is blocking, for now, so run the example with `janet -e` (def [pipe-r pipe-w ] (os/pipe ))
(:write pipe-w "hello" )
(:read pipe-r 5 )
# => @"hello"
# send the string "hello" into the writable stream
# part and read it back from the readable one