Skip to content

Commit

Permalink
Deprecate TrieSet.mem() in favor of TrieSet.has() (#576)
Browse files Browse the repository at this point in the history
This PR deprecates `TrieSet.mem()` in favor of `TrieSet.has()` for
consistency with the [base library design
document](https://github.com/dfinity/motoko-base/blob/master/doc/design.md#containers).

We could update the design guide if this makes more sense, although I
think `has` would be less ambiguous than `mem`, which could be
misunderstood as having something to do with "memory" instead of
"membership" for developers familiar with wording such as "has" /
"contains" / "includes".
  • Loading branch information
rvanasa authored Dec 6, 2023
1 parent 2c6956a commit 4a094f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/TrieSet.mo
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ module {
return true;
};

/// @deprecated: use `TrieSet.contains()`
///
/// Test if a set contains a given element.
public func mem<T>(s : Set<T>, x : T, xh : Hash, eq : (T, T) -> Bool) : Bool {
contains(s, x, xh, eq)
};

/// Test if a set contains a given element.
public func contains<T>(s : Set<T>, x : T, xh : Hash, eq : (T, T) -> Bool) : Bool {
switch (Trie.find<T, ()>(s, { key = x; hash = xh }, eq)) {
case null { false };
case (?_) { true }
Expand Down
5 changes: 5 additions & 0 deletions test/TrieSet.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ let simpleTests = do {
TrieSet.mem<Nat>(set1, 1, 1, Nat.equal),
M.equals(T.bool true)
),
Suite.test(
"contains",
TrieSet.contains<Nat>(set1, 1, 1, Nat.equal),
M.equals(T.bool true)
),
Suite.test(
"size",
TrieSet.size(set1),
Expand Down

0 comments on commit 4a094f9

Please sign in to comment.