Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(group-by
(fn [i ] (i :label ))
[{:label 'A :value 4 } {:label 'A :value 3 } {:label 'B :value 5 }])
# @{A @[{:label A :value 4} {:label A :value 3}] B @[{:label B :value 5}]}
(first [4 5 6 ]) # => 4 (for i 0 5
(print i ))
# 0
# 1
# 2
# 3
# 4
# => nil (map inc
(fiber/new |(each x (range 3 )
(yield x ))))
# => @[1 2 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
(def h ["a" "b" :c ]) # => ("a" "b" :c)
(find (fn [a ] (= "a" a )) h ) # => "a" (put (table ) :a 1 ) # => @{:a 1}
(os/clock ) # => 1.59384e+09 (peg/find ':d "Battery temperature: 40 °C" )
# => 21 index of the first number (freeze @"Ho" ) #=> "Ho"
(freeze ["Ho" ]) #=> ("Ho")
(freeze @["Ho" ]) #=> ("Ho")
(freeze @{"Ho" "Ho" }) #=> {"Ho" "Ho"}
(array/slice @[1 2 3 ] 0 0 ) # => @[]
(array/slice @[1 2 3 ] 0 1 ) # => @[1]
(array/slice @[1 2 3 ] 0 2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 3 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 4 ) # error: index out of range
(array/slice @[1 2 3 ] 1 1 ) # => @[]
(array/slice @[1 2 3 ] 1 2 ) # => @[2]
(array/slice @[1 2 3 ] 0 -1 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 -2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 -3 ) # => @[1]
(array/slice @[1 2 3 ] 0 -4 ) # => @[]
(array/slice @[1 2 3 ] 0 -5 ) # error: index out of range
# Match enables polymorphic functions:
(defn fac [& vars ]
(match vars
[0 ] 1
[x ] (* x (fac (- x 1 )))))
# from https://janet.guide/control-flow/
(defn calculate [expr ]
(match expr
[:add x y ] (+ x y )
[:subtract x y ] (- x y )
[:multiply x y ] (* x y )
([:divide x y ] (= y 0 )) (error "division by zero!" )
[:divide x y ] (/ x y )))
(calculate [:subtract 5 10 ])
# Note, it checks prefixes, so you must order things this way:
(match [1 2 ]
[x y z ] "three elements"
[x y ] "two elements"
[x ] "one element"
[] "no elements" )(def f (file/temp ))
(file/write f "ok stuff" )
(file/seek f :set 0 )
(file/read f :all )
# N.b. file/temp's file is not accessible outside of the process (flatten-into @[1 2 3 ] @[[4 5 6 ] @[7 8 9 ] @[10 11 12 ]]) # => @[1 2 3 4 5 6 7 8 9 10 11 12]
(some even? [1 3 5 7 11 18 ])
# =>
true