Take and Drop Items¶
take¶
@take(3:i32, (1,2,3,4,5,6):i32)
(1,2,3):i32
@take(-3:i32, (1,2,3,4,5,6):i32)
(4,5,6):i32
Function take
returns the leading n
items (when n is positive) or the tailing n
times (when n is negative) from a value v
.
If n
is greater than the length of v
, the extra slots are filled with the
default values depending on their current types.
Type Rules¶
Int, Any -> determined by the 2nd argument
_ , _ -> domain error
Shape Rules¶
drop¶
@drop(3:i32, (1,2,3,4,5,6):i32)
(4,5,6):i32
@drop(-3:i32, (1,2,3,4,5,6):i32)
(1,2,3):i32
Function drop
drops
the leading n
(when n is positive) or
the tailing n
(when n is negative) from
a value v
and returns the remaining values.
If n
is greater or equal to the length of v
, an empty value is returned.
Type Rules¶
Int, Any -> determined by the 2nd argument
_ , _ -> domain error
Shape Rules¶
Discussion¶
- Function
take
anddrop
are interchangable in some casestake(3,x)
is the same asdrop(len(x)-3,x)
iflen(x)>=3