on 492ae2f help sign in
41 lines 628 B history raw
1### `++snag`
3Index
5Accepts an atom `a` and a `++list` `b`, producing the element at the index
6of `a`and failing if the list is null. Lists are 0-indexed.
8Accepts
9-------
11`b` is a list.
13Produces
14--------
16Produces an element of `b`, or crashes if no element exists at that index.
18Source
19------
21 ++ snag :: index
22 ~/ %snag
23 |* {a/@ b/(list)}
24 |-
25 ?~ b
26 ~|('snag-fail' !!)
27 ?: =(0 a) i.b
28 $(b t.b, a (dec a))
31Examples
32--------
34 ~zod/try=> (snag 2 "asdf")
35 ~~d
36 ~zod/try=> (snag 0 `(list ,@ud)`~[1 2 3 4])
37 1
41***