firsts

HC Data Structure Primitives Selectors firsts
BitItem butFirsts

firsts list


outputs a list containing the first of each member of the input list. It is an error if any member of the input list is empty. (The input itself may be empty, in which case the output is also empty.) This could be written as

to firsts :list
	output map "first :list
end

but is provided as a primitive in order to speed up the iteration tools MAP, map_se, and foreach.

New in 4.689 is that Array arguments are now allowed.

Examples:

show firsts [[H a l l o] [W o r l d]]		;[H W]

to transpose :matrix
	if emptyp first :matrix [op []]
	op fput firsts :matrix transpose bfs :matrix
end

show firsts {{1 2 3}[a b c]}		;{1 a}

Reference:

BitItem butFirsts