let choose s p x =
let result = ref (Obj.magic 1) in
try
iter s
(fun y ->
match p y with
| Some(z) ->
result := z;
raise Found
| None -> ())
x;
raise Not_found
with
Found -> !result