[back]

All Map

Implement the function

val all_map : ('a -> 'b option) -> 'a list -> 'b list option

so that all_map f l is

Your solution must be tail recursive.

Examples

let f x = if x > 0 then Some (x * x) else None
let _ = assert (all_map f [1;2;3] = Some [1;4;9])
let _ = assert (all_map f [1;-1;3] = None)
let _ = assert (all_map f [] = Some [])