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 filterMap_of_filterMap : forall (f : B -> option C) (g : A -> option B) xs, filterMap f (filterMap g xs) = filterMap (fun a => match g a with | Some b => f b | None => None end) xs.