Skip to content

Commit

Permalink
Refactor map functions to remove unnecessary type constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Mar 19, 2024
1 parent 2c876fd commit 495d80d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions map/map.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ pub fn iter[K : Compare, V](self : Map[K, V], f : (K, V) -> Unit) -> Unit {
}

/// Iterate over the key-value pairs with index.
pub fn iteri[K : Compare, V](self : Map[K, V], f : (Int, K, V) -> Unit) -> Unit {
fn do_iteri(m : Map[K, V], f : (Int, K, V) -> Unit, i : Int) {
pub fn iteri[K, V](self : Map[K, V], f : (Int, K, V) -> Unit) -> Unit {
fn do_iteri(m : Map[K, V], f, i) {
match m {
Empty => ()
Tree(k, v, _, l, r) => {
Expand All @@ -184,15 +184,15 @@ pub fn iteri[K : Compare, V](self : Map[K, V], f : (Int, K, V) -> Unit) -> Unit
}

/// Maps over the values in the map.
pub fn map[K : Compare, X, Y](self : Map[K, X], f : (X) -> Y) -> Map[K, Y] {
pub fn map[K , X, Y](self : Map[K, X], f : (X) -> Y) -> Map[K, Y] {
match self {
Empty => Empty
Tree(k, v, s, l, r) => Tree(k, f(v), s, map(l, f), map(r, f))
}
}

/// Maps over the key-value pairs in the map.
pub fn map_with_key[K : Compare, X, Y](
pub fn map_with_key[K , X, Y](
self : Map[K, X],
f : (K, X) -> Y
) -> Map[K, Y] {
Expand Down

0 comments on commit 495d80d

Please sign in to comment.