[m-rev.] for review: map.select_unselect
Julien Fischer
jfischer at opturion.com
Wed Jun 5 20:43:14 AEST 2019
On Wed, 5 Jun 2019, Zoltan Somogyi wrote:
> For review by anyone. The code is mostly straightforward; I am looking
> for feedback mostly about the name of the predicate (which I intend to use
> in an upcoming change).
I think the names are fine (or at least I failed to thing up anything
better).
> Add map.select_unselect and map.select_unselect_sorted_list.
>
> library/map.m:
> As above.
>
> NEWS:
> Announce the new predicates.
>
> diff --git a/library/map.m b/library/map.m
> index 49f6c03..750688b 100644
> --- a/library/map.m
> +++ b/library/map.m
> @@ -338,12 +338,29 @@
> :- func select(map(K, V), set(K)) = map(K, V).
> :- pred select(map(K, V)::in, set(K)::in, map(K, V)::out) is det.
>
> + % select_unselect takes a map and a set of keys, and returns two maps:
> + % the first containing the keys in the set and their corresponding values,
> + % the second containing the keys NOT in the set and their corresponding
> + % values.
> + %
> +:- pred select_unselect(map(K, V)::in, set(K)::in,
> + map(K, V)::out, map(K, V)::out) is det.
> +
> % select_sorted_list takes a map and a sorted list of keys, and returns
> % a map containing the keys in the list and their corresponding values.
> %
> :- func select_sorted_list(map(K, V), list(K)) = map(K, V).
> :- pred select_sorted_list(map(K, V)::in, list(K)::in, map(K, V)::out) is det.
>
> + % select_unselect_sorted_list takes a map and a sorted list of keys,
> + % and returns two maps:
> + % the first containing the keys in the list and their corresponding values,
> + % the second containing the keys NOT in the list and their corresponding
> + % values.
What if the list contains duplicate elements?
Could you please also add a test cases the exercises the new predicates.
(Or extend an existing on if appropriate.)
Julien.
More information about the reviews
mailing list