Skip to content

Commit

Permalink
Attempt to return originally elements from closure
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Sep 15, 2019
1 parent 1fb4912 commit 56ef00a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/top_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ module Make(Keys : Keys)(Monad : Monad.S) = struct
in
iter_elts elements ~temporarily_marked:Keys.empty
>>= function
| Ok () -> return (Ok (List.rev !res))
| Ok () ->
let res =
List.map !res ~f:(fun candidate ->
let candidate_set = Keys.add Keys.empty (key candidate) in
List.find_map elements ~f:(fun elem ->
let elem_key = key elem in
Option.some_if (Keys.mem candidate_set elem_key) elem)
|> Option.value ~default:candidate)
in
return (Ok (List.rev res))
| Error elts -> return (Error elts)
end [@@inlined always]

Expand Down

0 comments on commit 56ef00a

Please sign in to comment.