Fixpoint filterMap {A B} (f : A -> option B) (l : list A) : list B :=
  match l with
    | [] => []
    | x :: xs => match f x with
                   | None => filterMap f xs
                   | Some y => y :: filterMap f xs
                 end
  end.

Lemma map_of_filterMap : forall (f : A -> option B) (g : B -> C) l, map g (filterMap f l) = filterMap (fun x => match f x with | Some y => Some (g y) | None => None end) l.