This project is read-only.
Using .iter

Category:
Functions - Arrays, Lists, Seqs
Description: .iter applies a given function to each element in the collection, returning a value of unit ().
Code:
let AggregateExample1() =
let aoList = [ for i in 1..5 -> (i, i*i) ]
let aoArray = [| for i in 1..5 -> (i, i*i) |]
let aoSeq = seq { for i in 1..5 -> (i, i*i) }

printf "aoList: "
List.iter (fun (a,b) -> printf "(%d, %d) " a b) aoList
printf "\naoArray: "
Array.iter (fun (a,b) -> printf "(%d, %d) " a b) aoArray
printf "\naoSeq: "
Seq.iter (fun (a,b) -> printf "(%d, %d) " a b) aoSeq

Execution Result:
aoList: (1, 1) (2, 4) (3, 9) (4, 16) (5, 25) 
aoArray: (1, 1) (2, 4) (3, 9) (4, 16) (5, 25)
aoSeq: (1, 1) (2, 4) (3, 9) (4, 16) (5, 25)

Last edited Sep 14, 2011 at 3:52 AM by ttliu2000, version 1

Comments

No comments yet.