Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(seq [i :range [0 3 ]
j :range [0 3 ]]
[(keyword (string/format "%c" (+ 97 i )))
j ])
# => '@[(:a 0) (:a 1) (:a 2) (:b 0) (:b 1) (:b 2) (:c 0) (:c 1) (:c 2)] # Suppose you have a fiber that yields chunks of paginated api results:
(def api-results (fiber/new (fn [] (yield [1 2 3 ]) (yield [4 5 6 ]))))
# Using :iterate, the right side of the binding is evaluated each time the loop is run,
# which allows for running a side-effecting expression that may be different each time.
(loop [_ :iterate (fiber/can-resume? api-results )] (pp (resume api-results )))
# This example can be simplified using :generate
(loop [chunk :generate api-results ] (pp chunk ))
(find |(string/has-prefix? "a" $ ) ["be" "cat" "art" "apple" ])
# => "art"
(-> 1 (< 2 )) # -> true
(->> 1 (< 2 )) # -> false (defn slurp-lines [path ]
(string/split "\n" (slurp path )))(def cc (ev/thread-chan 99 )) # Sets up a message channel.
(def ww (filewatch/new cc )) # Creates the watcher.
(filewatch/add ww "ftest.janet" :all ) # Watch for all changes.
(filewatch/add ww "fadd.janet" :modify ) # Only care if modified.
(filewatch/listen ww ) # Start filewatcher listening for changes.
# Note that we may still get events for files that have been removed
# so we have to make sure we don't remove them twice.
(var careless "Have we already removed %fadd.janet?" false )
(forever
(let (item (ev/take cc ))
(pp (ev/take cc ))
(when (and (not careless ) (= "fadd.janet" (item :wd-path )))
(print "I don't care about this file anymore." )
(filewatch/remove ww (item :wd-path ))
(set careless true )
)))(do
(def coll @[])
(forv i 0 9
(array/push coll i )
(+= i 2 ))
coll )
# => @[0 3 6]
(math/round 1.1 ) # => 1
(map math/round [1.49 1.50 1.51 ]) # => @[1 2 2]
# wrap short-fn / |
(->> 10
(|(/ $ 2 )))
# =>
5
# also wrap fn
(->> 10
((fn [n ] (/ n 2 ))))
# =>
5 (reduce string "ha" ["ha" "ha" "ha" "ha" ]) # => "hahahahaha"
(accumulate string "ha" ["ha" "ha" "ha" "ha" ]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"] (->
{:a [1 2 3 ] :b [4 5 6 ]}
(get :a )
(sum )
(string " is the result" ))
# -> "6 is the result"
# same as:
(string (sum (get {:a [1 2 3 ] :b [4 5 6 ]} :a ))" is the result" )
(def a @[23 42 ])
(array/clear a )
(pp a )
# => prints @[] (string/bytes "foo" ) # => (102 111 111)
(string/from-bytes 102 111 111 ) # => "foo"
(string/from-bytes (splice (string/bytes "foo" ))) # => "foo"
(map (fn [x ] x ) "foo" ) # => @[102 111 111]
(map string/from-bytes "foo" ) # => @["f" "o" "o"]
(defn string/explode [s ] (map string/from-bytes s ))
(string/explode "foo" ) # => @["f" "o" "o"]
(table/clear @{:a 1 :b 2 })
# => @{}
# Convert an array of k/v pairs into a table
(def kvp @[[:foo 1 ] [:bar 2 ]])
(table ;(mapcat identity kvp )) # => @{:foo 1 :bar 2}