Skip to content

Commit

Permalink
Merge pull request #4 from serokell/wip/s-and-witch/76-ordered-map-un…
Browse files Browse the repository at this point in the history
…it-tests

[DMS-76] Persistent ordered map unit testing
  • Loading branch information
s-and-witch authored Sep 24, 2024
2 parents 0ea2e48 + 9bbf508 commit 782342c
Show file tree
Hide file tree
Showing 2 changed files with 545 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/PersistentOrderedMap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ module {
}
};

/// Create a new empty map.
public func empty<K, V>() : Map<K, V> = #leaf;

/// Returns an Iterator (`Iter`) over the key-value pairs in the map.
/// Iterator provides a single method `next()`, which returns
/// pairs in no specific order, or `null` when out of pairs to iterate over.
Expand All @@ -146,14 +149,14 @@ module {
/// Returns an Iterator (`Iter`) over the keys of the map.
/// Iterator provides a single method `next()`, which returns
/// keys in no specific order, or `null` when out of keys to iterate over.
public func keys<K, V>(m : Map<K, V>, direction : Direction) : I.Iter<K>
= I.map(iter(m, direction), func(kv : (K, V)) : K {kv.0});
public func keys<K, V>(m : Map<K, V>) : I.Iter<K>
= I.map(entries(m), func(kv : (K, V)) : K {kv.0});

/// Returns an Iterator (`Iter`) over the values of the map.
/// Iterator provides a single method `next()`, which returns
/// values in no specific order, or `null` when out of values to iterate over.
public func vals<K, V>(m : Map<K, V>, direction : Direction) : I.Iter<V>
= I.map(iter(m, direction), func(kv : (K, V)) : V {kv.1});
public func vals<K, V>(m : Map<K, V>) : I.Iter<V>
= I.map(entries(m), func(kv : (K, V)) : V {kv.1});

/// Creates a new map by applying `f` to each entry in `rbMap`. Each entry
/// `(k, v)` in the old map is transformed into a new entry `(k, v2)`, where
Expand Down
Loading

0 comments on commit 782342c

Please sign in to comment.