From 3893b8d950d506caf220b8d42baf9bd171219e3e Mon Sep 17 00:00:00 2001 From: Flavio Brasil Date: Thu, 7 Dec 2023 22:31:07 -0800 Subject: [PATCH] lists: more consistent names --- README.md | 6 +++--- kyo-core/shared/src/main/scala/kyo/lists.scala | 8 ++++---- .../src/test/scala/kyoTest/listsTest.scala | 16 ++++++++-------- .../src/test/scala/kyoTest/directTest.scala | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a1a31bf0e..3b354ab3e 100644 --- a/README.md +++ b/README.md @@ -592,16 +592,16 @@ The `Lists` effect is designed to aid in handling and exploring multiple options import kyo.lists._ // Evaluate each of the provided lists. -// Note how 'foreach' takes a 'List[T]' +// Note how 'get' takes a 'List[T]' // and returns a 'T > Lists' val a: Int > Lists = - Lists.foreach(List(1, 2, 3, 4)) + Lists.get(List(1, 2, 3, 4)) // 'dropIf' discards the current choice if // a condition is not met. Produces a 'List(1, 2)' // since values greater than 2 are dropped val b: Int > Lists = - a.map(v => Lists.dropIf(v > 2).map(_ => v)) + a.map(v => Lists.filter(v > 2).map(_ => v)) // 'drop' unconditionally discards the // current choice. Produces a 'List(42)' diff --git a/kyo-core/shared/src/main/scala/kyo/lists.scala b/kyo-core/shared/src/main/scala/kyo/lists.scala index 5d2c64b22..3b15df782 100644 --- a/kyo-core/shared/src/main/scala/kyo/lists.scala +++ b/kyo-core/shared/src/main/scala/kyo/lists.scala @@ -16,7 +16,7 @@ object lists { def loop(l: List[T], acc: List[List[U]]): U > (Lists with S) = l match { case Nil => - Lists.foreach(acc.reverse.flatten: List[U]) + Lists.get(acc.reverse.flatten: List[U]) case t :: ts => import Flat.unsafe._ Lists.run[U, S](f(t)).map(l => loop(ts, l :: acc)) @@ -29,15 +29,15 @@ object lists { handle[T, S, Any](v) def repeat(n: Int): Unit > Lists = - foreach(List.fill(n)(())) + get(List.fill(n)(())) - def foreach[T, S](v: List[T] > S): T > (Lists with S) = + def get[T, S](v: List[T] > S): T > (Lists with S) = v.map { case head :: Nil => head case _ => suspend(v) } - def dropIf[S](v: Boolean > S): Unit > (Lists with S) = + def filter[S](v: Boolean > S): Unit > (Lists with S) = v.map { case true => () diff --git a/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala index 9a164b496..1f015a1c9 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala @@ -9,37 +9,37 @@ class listsTest extends KyoTest { "one" in { assert( - Lists.run(Lists.foreach(List(1)).map(_ + 1)) == + Lists.run(Lists.get(List(1)).map(_ + 1)) == List(2) ) } "multiple" in { assert( - Lists.run(Lists.foreach(List(1, 2, 3)).map(_ + 1)) == + Lists.run(Lists.get(List(1, 2, 3)).map(_ + 1)) == List(2, 3, 4) ) } "nested" in { assert( - Lists.run(Lists.foreach(List(1, 2, 3)).map(i => - Lists.foreach(List(i * 10, i * 100)) + Lists.run(Lists.get(List(1, 2, 3)).map(i => + Lists.get(List(i * 10, i * 100)) )) === List(10, 100, 20, 200, 30, 300) ) } "drop" in { assert( - Lists.run(Lists.foreach(List(1, 2, 3)).map(i => + Lists.run(Lists.get(List(1, 2, 3)).map(i => if (i < 2) Lists.drop - else Lists.foreach(List(i * 10, i * 100)) + else Lists.get(List(i * 10, i * 100)) )) == List(20, 200, 30, 300) ) } "filter" in { assert( - Lists.run(Lists.foreach(List(1, 2, 3)).map(i => - Lists.dropIf(i >= 2).map(_ => Lists.foreach(List(i * 10, i * 100))) + Lists.run(Lists.get(List(1, 2, 3)).map(i => + Lists.filter(i >= 2).map(_ => Lists.get(List(i * 10, i * 100))) )) == List(20, 200, 30, 300) ) diff --git a/kyo-direct/src/test/scala/kyoTest/directTest.scala b/kyo-direct/src/test/scala/kyoTest/directTest.scala index 98fa79ec2..ac027d8e2 100644 --- a/kyo-direct/src/test/scala/kyoTest/directTest.scala +++ b/kyo-direct/src/test/scala/kyoTest/directTest.scala @@ -153,8 +153,8 @@ class directTest extends KyoTest { "lists" in { import kyo.lists._ - val x = Lists.foreach(List(1, -2, -3)) - val y = Lists.foreach(List("ab", "cde")) + val x = Lists.get(List(1, -2, -3)) + val y = Lists.get(List("ab", "cde")) val v: Int > Lists = defer { @@ -172,8 +172,8 @@ class directTest extends KyoTest { "lists + filter" in { import kyo.lists._ - val x = Lists.foreach(List(1, -2, -3)) - val y = Lists.foreach(List("ab", "cde")) + val x = Lists.get(List(1, -2, -3)) + val y = Lists.get(List("ab", "cde")) val v: Int > Lists = defer { @@ -183,7 +183,7 @@ class directTest extends KyoTest { if (xx > 0) await(y).length * await(x) else await(y).length ) - await(Lists.dropIf(r > 0)) + await(Lists.filter(r > 0)) r }