From 23bdd9753d715dcd330609b42fc1026bba257746 Mon Sep 17 00:00:00 2001 From: YubinChen Date: Thu, 20 Jun 2024 14:09:27 +0800 Subject: [PATCH] rename forall/exists to all/any in sorted_set --- immut/sorted_set/README.md | 8 ++++---- immut/sorted_set/immutable_set.mbt | 12 ++++++------ immut/sorted_set/immutable_set_test.mbt | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/immut/sorted_set/README.md b/immut/sorted_set/README.md index 1a3c0a265..974094ff9 100644 --- a/immut/sorted_set/README.md +++ b/immut/sorted_set/README.md @@ -116,13 +116,13 @@ ImmutableSet::[1, 2, 3, 4, 5].fold(0, fn(acc, x) { acc + x }) // 15 ImmutableSet::[1, 2, 3].map(fn(x){ x * 2}) // ImmutableSet::[2, 4, 6] ``` -### Forall & Exists +### All & Any -`forall` and `exists` can detect whether all elements in the set match or if there are elements that match. +`all` and `any` can detect whether all elements in the set match or if there are elements that match. ```moonbit -ImmutableSet::[2, 4, 6].forall(fn(v) { v % 2 == 0}) // true -ImmutableSet::[1, 4, 3].exists(fn(v) { v % 2 == 0}) // true +ImmutableSet::[2, 4, 6].all(fn(v) { v % 2 == 0}) // true +ImmutableSet::[1, 4, 3].any(fn(v) { v % 2 == 0}) // true ``` ### Stringify diff --git a/immut/sorted_set/immutable_set.mbt b/immut/sorted_set/immutable_set.mbt index cbdae76f2..58f344459 100644 --- a/immut/sorted_set/immutable_set.mbt +++ b/immut/sorted_set/immutable_set.mbt @@ -469,14 +469,14 @@ pub fn map[T : Compare, U : Compare]( /// # Example /// /// ``` -/// println(ImmutableSet::[2, 4, 6].forall(fn(v) { v % 2 == 0})) +/// println(ImmutableSet::[2, 4, 6].all(fn(v) { v % 2 == 0})) /// // output: true /// ``` -pub fn forall[T : Compare](self : ImmutableSet[T], f : (T) -> Bool) -> Bool { +pub fn all[T : Compare](self : ImmutableSet[T], f : (T) -> Bool) -> Bool { match self { Empty => true Node(~left, ~value, ~right, ..) => - f(value) && left.forall(f) && right.forall(f) + f(value) && left.all(f) && right.all(f) } } @@ -485,14 +485,14 @@ pub fn forall[T : Compare](self : ImmutableSet[T], f : (T) -> Bool) -> Bool { /// # Example /// /// ``` -/// println(ImmutableSet::[1, 4, 3].exists(fn(v) { v % 2 == 0})) +/// println(ImmutableSet::[1, 4, 3].any(fn(v) { v % 2 == 0})) /// // output: true /// ``` -pub fn exists[T : Compare](self : ImmutableSet[T], f : (T) -> Bool) -> Bool { +pub fn any[T : Compare](self : ImmutableSet[T], f : (T) -> Bool) -> Bool { match self { Empty => false Node(~left, ~value, ~right, ..) => - f(value) || left.exists(f) || right.exists(f) + f(value) || left.any(f) || right.any(f) } } diff --git a/immut/sorted_set/immutable_set_test.mbt b/immut/sorted_set/immutable_set_test.mbt index bc985210d..0ceee8544 100644 --- a/immut/sorted_set/immutable_set_test.mbt +++ b/immut/sorted_set/immutable_set_test.mbt @@ -107,14 +107,14 @@ test "map" { )? } -test "forall" { - inspect(ImmutableSet::[2, 4, 6].forall(fn(v) { v % 2 == 0 }), content="true")? - inspect(ImmutableSet::[1, 3, 5].forall(fn(v) { v % 2 == 0 }), content="false")? +test "all" { + inspect(ImmutableSet::[2, 4, 6].all(fn(v) { v % 2 == 0 }), content="true")? + inspect(ImmutableSet::[1, 3, 5].all(fn(v) { v % 2 == 0 }), content="false")? } -test "exists" { - inspect(ImmutableSet::[1, 4, 3].exists(fn(v) { v % 2 == 0 }), content="true")? - inspect(ImmutableSet::[1, 5, 3].exists(fn(v) { v % 2 == 0 }), content="false")? +test "any" { + inspect(ImmutableSet::[1, 4, 3].any(fn(v) { v % 2 == 0 }), content="true")? + inspect(ImmutableSet::[1, 5, 3].any(fn(v) { v % 2 == 0 }), content="false")? } test "fold" {