ZVON > References > Haskell reference
| Indexes | Syntax | >> Prelude << | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Prelude
Function: take
Type: Int -> [a] -> [a]
Description: creates a list, the first argument determines, how many items should be taken from the list passed as the second argument
Related: cycle, iterate, repeat, replicate

Example 1

Input: take 5 [1,2,3,4,5,6,7]

Output: [1,2,3,4,5]

Example 2

Input: take 5 [1,2]

Output: [1,2]

Example 3

Input: take 0 [1,2,3,4,5,6,7]

Output: []

Example 4

Input: take 5 (repeat 3)

Output: [3,3,3,3,3]

Example 5

Input: take 10 (iterate (2*) 1)

Output: [1,2,4,8,16,32,64,128,256,512]

Example 6

Input: take 10 (cycle [1,2,3])

Output: [1,2,3,1,2,3,1,2,3,1]