Skip to content

Take ​

Generated from the engine's own definition: compute-engine's symbol, which we neither extend nor document by hand.

Return n elements from a collection.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageTake!
Take((xs: T, count: number) -> T where T: string) & ((xs: indexed_collection<T>, count: number) -> list<T> where T)as compute-engine declares it
Typed signatures
TypePackageApplies
((xs: T, count: number) -> T where T: string) & ((xs: indexed_collection<T>, count: number) -> list<T> where T)compute-enginealways

Domain: Compute engine

Examples

3 more kept as data, checked against the oracles
Basic #

The first four elements

live ↗
InTake([a,b,c,d,k,f],4)\mathrm{Take}(\bigl\lbrack a, b, c, d, k, f\bigr\rbrack, 4)Out[a,b,c,d]\bigl\lbrack a, b, c, d\bigr\rbrack

A negative count takes from the end

live ↗
InTake([a,b,c,d,k,f],−3)\mathrm{Take}(\bigl\lbrack a, b, c, d, k, f\bigr\rbrack, -3)Out[d,k,f]\bigl\lbrack d, k, f\bigr\rbrack
Scope #

Taking from the first level of a matrix keeps whole rows

live ↗
InTake([[11,12,13],[21,22,23],[31,32,33]],2)\mathrm{Take}(\bigl\lbrack\bigl\lbrack11, 12, 13\bigr\rbrack, \bigl\lbrack21, 22, 23\bigr\rbrack, \bigl\lbrack31, 32, 33\bigr\rbrack\bigr\rbrack, 2)Out[[11,12,13],[21,22,23]]\bigl\lbrack\bigl\lbrack11, 12, 13\bigr\rbrack, \bigl\lbrack21, 22, 23\bigr\rbrack\bigr\rbrack

UpTo takes at most that many, so no error

live ↗
InTake([a,b,c],UpTo(4))\mathrm{Take}(\bigl\lbrack a, b, c\bigr\rbrack, \mathrm{UpTo}(4))Out[a,b,c]\bigl\lbrack a, b, c\bigr\rbrack
Properties #

A longer list truncates at 4

live ↗
InTake([a,b,c,d,k,f,g,h],4)\mathrm{Take}(\bigl\lbrack a, b, c, d, k, f, g, h\bigr\rbrack, 4)Out[a,b,c,d]\bigl\lbrack a, b, c, d\bigr\rbrack
Possible issues #

Negative one gives just the last element

live ↗
InTake([a,b,c,d,k],−1)\mathrm{Take}(\bigl\lbrack a, b, c, d, k\bigr\rbrack, -1)Out[k]\bigl\lbrack k\bigr\rbrack
About
Examples9
Checked againstWolfram Language 7 agree2 differ
CrosswalkWolfram Language