Lists and 'map'

Category:
Lists, Tuples and Options
Description: String23'
Code:
let ListSample2() =
let data = [1;2;3;4]
let r1 = data |> List.map (fun x -> x + 1)
printfn "Adding '1' using map = %A" r1
let r2 = data |> List.map string
printfn "Converting to strings using map = %A" r2
let r3 = data |> List.map (fun x -> (x,x))
printfn "Tupling up using map = %A" r3

Execution Result:
Adding '1' using map = [2; 3; 4; 5]
Converting to strings using map = ["1"; "2"; "3"; "4"]
Tupling up using map = [(1, 1); (2, 2); (3, 3); (4, 4)]

Last edited Sep 14, 2011 at 2:49 AM by ttliu2000, version 1

Comments

No comments yet.