Skip to content

Commit

Permalink
Add mapRemoveAll to basic spells
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt authored Aug 7, 2023
1 parent fd9bcda commit cba4f72
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion examples/spells/basicSpells.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,21 @@ module basicSpells {
assert(Map(3 -> 4, 7 -> 8) == Map(3 -> 4, 5 -> 6, 7 -> 8).mapRemove(5)),
assert(Map() == Map().mapRemove(3)),
}
}

/// Removes a set of map entry.
///
/// - @param __map a map to remove an entry from
/// - @param __keys a set of keys to remove from the map
/// - @returns a new map that contains all entries of __map
/// that do not have a key in __keys
pure def mapRemoveAll(__map: a -> b, __keys: Set[a]): a -> b = {
__map.keys().exclude(__keys).mapBy(__k => __map.get(__k))
}

run mapRemoveAllTest =
val m = Map(3 -> 4, 5 -> 6, 7 -> 8)
all {
assert(m.mapRemoveAll(Set(5, 7)) == Map(3 -> 4)),
assert(m.mapRemoveAll(Set(5, 99999)) == Map(3 -> 4, 7 -> 8)),
}
}

0 comments on commit cba4f72

Please sign in to comment.