let apply_opted f v = match f with
    | None -> None
    | Some f -> Some (f v)