I came across this function : List.map. What I have understood is that List.map takes a function and a list as an argument and transforms each element in the list.
List.iter does something similar (maybe?), For reference see the example below.:
# let f elem =
Printf.printf "I'm looking at element %d now\n" elem in
List.iter f my_list;;
I'm looking at element 1 now
I'm looking at element 2 now
I'm looking at element 3 now
I'm looking at element 4 now
I'm looking at element 5 now
I'm looking at element 6 now
I'm looking at element 7 now
I'm looking at element 8 now
I'm looking at element 9 now
I'm looking at element 10 now
- : unit = ()
Can someone explain the difference between List.map and List.iter?
NOTE: I am new to OCaml and functional programming.