Skip to content

Commit 18dc7cd

Browse files
authored
Merge pull request #286 from rwtolbert/example_eachp
add examples for eachp
2 parents d97afda + 7544e5c commit 18dc7cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

examples/eachp.janet

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# keys for tuple/array are 0-based index
2+
# prints 0->:a 1->:b 2->:c 3->:d 4->:e
3+
(eachp [i x] [:a :b :c :d :e] (prinf "%v->%v " i x)) # -> nil
4+
5+
# prints 0->"a" 1->"b" 2->"c" 3->"d" 4->"e"
6+
(eachp [i x] @["a" "b" "c" "d" "e"] (prinf "%v->%v " i x)) # -> nil
7+
8+
# key, value from table/struct in an unspecified order
9+
# prints :b -> 2 :a -> 1
10+
(eachp [k v] {:a 1 :b 2} (prinf "%v -> %v " k v)) # -> nil
11+
12+
# prints :foo -> "A" :bar -> "B"
13+
(eachp [k v] @{:foo "A" :bar "B"} (prinf "%v -> %v " k v)) # -> nil

0 commit comments

Comments
 (0)