first, last¶
first¶
First item of a list
first x first[x]
Where x is a list or dictionary, returns its first item; otherwise x.
Use first with Each to get the first item of each item of a list, or of each key in a dictionary.
q)first 1 2 3 4 5
1
q)first 42
42
q)RaggedArray:(1 2 3;4 5;6 7 8 9;0)
q)first each RaggedArray
1 4 6 0
q)RaggedDict:`a`b`c!(1 2;3 4 5;"hello")
q)first RaggedDict / value of first key
1 2
q)first each RaggedDict
a| 1
b| 3
c| "h"
Where x is an empty vector, returns a null of its type.
q)first `long$()
0N
q)first ""
" "
Where x is a table, returns its first row as a dictionary.
q)sp:([]s:`s1`s1`s2;p:`p1`p2`p1;qty:300 200 400)
q)first sp
s | `s1
p | `p1
qty| 300
A keyed table is a dictionary, so first returns the first row of its value columns, without the key.
q)first ([k:1 2]v:3 4)
v| 3
first is the dual to enlist.
q)a:10
q)a~first enlist 10
1b
q)a~first first enlist enlist 10
1b
first is an aggregate function.
last¶
Last item of a list
last x last[x]
Where x is a list or dictionary, returns its last item; otherwise x.
q)last til 10
9
q)last `a`b`c!1 2 3
3
q)last 42
42