Skip to content

Commit

Permalink
deprecate immut/sorted_map.empty (#1310)
Browse files Browse the repository at this point in the history
* deprecate @immut/sorted_map.empty and use new instead

* fix warnings
  • Loading branch information
Yoorkin authored Dec 9, 2024
1 parent f60be25 commit 53ad7e2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion immut/sorted_map/map.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ test "filter_with_key" {
}

test "empty" {
let m : T[Int, Int] = empty()
let m : T[Int, Int] = T::new()
assert_eq!(m.debug_tree(), "_")
}

Expand Down
2 changes: 1 addition & 1 deletion immut/sorted_map/map_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test "size" {
}

test "is_empty" {
let m : @sorted_map.T[Int, Int] = @sorted_map.empty()
let m : @sorted_map.T[Int, Int] = @sorted_map.new()
assert_eq!(m.is_empty(), true)
let m = m.add(1, 1)
assert_eq!(m.is_empty(), false)
Expand Down
3 changes: 2 additions & 1 deletion immut/sorted_map/sorted_map.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl T {
each[K, V](Self[K, V], (K, V) -> Unit) -> Unit
eachi[K, V](Self[K, V], (Int, K, V) -> Unit) -> Unit
elems[K, V](Self[K, V]) -> Array[V]
empty[K, V]() -> Self[K, V]
empty[K, V]() -> Self[K, V] //deprecated
filter[K : Compare, V](Self[K, V], (V) -> Bool) -> Self[K, V]
filter_with_key[K : Compare, V](Self[K, V], (K, V) -> Bool) -> Self[K, V]
fold[K, V, A](Self[K, V], init~ : A, (A, V) -> A) -> A
Expand All @@ -30,6 +30,7 @@ impl T {
lookup[K : Compare, V](Self[K, V], K) -> V?
map[K, X, Y](Self[K, X], (X) -> Y) -> Self[K, Y]
map_with_key[K, X, Y](Self[K, X], (K, X) -> Y) -> Self[K, Y]
new[K, V]() -> Self[K, V]
of[K : Compare, V](FixedArray[(K, V)]) -> Self[K, V]
op_get[K : Compare, V](Self[K, V], K) -> V?
remove[K : Compare, V](Self[K, V], K) -> Self[K, V]
Expand Down
4 changes: 2 additions & 2 deletions immut/sorted_map/traits_impl.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

///|
pub impl[K, V] Default for T[K, V] with default() { empty() }
pub impl[K, V] Default for T[K, V] with default() { T::new() }

///|
pub impl[K : Eq, V : Eq] Eq for T[K, V] with op_equal(self, other) -> Bool {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub impl[V : @json.FromJson] @json.FromJson for T[String, V] with from_json(
) {
match json {
Object(obj) => {
let mut map = T::empty()
let mut map = T::new()
for k, v in obj {
map = map.add(k, V::from_json!(v, path))
}
Expand Down
11 changes: 8 additions & 3 deletions immut/sorted_map/utils.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///|
/// Create an empty map.
///| Create an empty map.
/// @alert deprecated "Use `new()` instead"
pub fn T::empty[K, V]() -> T[K, V] {
Empty
}

///| Create an empty map.
pub fn T::new[K, V]() -> T[K, V] {
Empty
}

///|
/// Create a map with a single key-value pair.
pub fn T::singleton[K, V](key : K, value : V) -> T[K, V] {
Expand Down Expand Up @@ -248,7 +253,7 @@ pub fn iter2[K, V](self : T[K, V]) -> Iter2[K, V] {

///|
pub fn T::from_iter[K : Compare, V](iter : Iter[(K, V)]) -> T[K, V] {
iter.fold(init=T::empty(), fn(m, e) { m.add(e.0, e.1) })
iter.fold(init=T::new(), fn(m, e) { m.add(e.0, e.1) })
}

///|
Expand Down
4 changes: 2 additions & 2 deletions immut/sorted_map/utils_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test "iter" {
}

test "op_get with empty map" {
let map : @sorted_map.T[Int, String] = @sorted_map.empty()
let map : @sorted_map.T[Int, String] = @sorted_map.new()
assert_eq!(map[3], None)
}

Expand All @@ -89,7 +89,7 @@ test "to_json with non-empty map" {
}

test "to_json with empty map" {
let map : @sorted_map.T[Int, String] = @sorted_map.empty()
let map : @sorted_map.T[Int, String] = @sorted_map.new()
@json.inspect!(map.to_json(), content={})
}

Expand Down

0 comments on commit 53ad7e2

Please sign in to comment.