diff --git a/indigo/indigo/src/main/scala/indigo/shared/collections/Batch.scala b/indigo/indigo/src/main/scala/indigo/shared/collections/Batch.scala index 909ea9205..84bf3491f 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/collections/Batch.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/collections/Batch.scala @@ -60,6 +60,12 @@ sealed trait Batch[+A]: given CanEqual[B, B] = CanEqual.derived _jsArray.exists(_ == p) + def distinct: Batch[A] = + Batch(_jsArray.distinct) + + def distinctBy[B](f: A => B): Batch[A] = + Batch(_jsArray.distinctBy(f)) + def take(n: Int): Batch[A] = Batch.Wrapped(_jsArray.take(n)) diff --git a/indigo/indigo/src/test/scala/indigo/shared/collections/BatchTests.scala b/indigo/indigo/src/test/scala/indigo/shared/collections/BatchTests.scala index 7db5a8475..170a5c72d 100644 --- a/indigo/indigo/src/test/scala/indigo/shared/collections/BatchTests.scala +++ b/indigo/indigo/src/test/scala/indigo/shared/collections/BatchTests.scala @@ -488,4 +488,13 @@ class BatchTests extends munit.FunSuite { assertEquals(Batch.Combine(Batch.empty[Int], Batch.empty[Int]).lastOption, None) } + test("distinct") { + assertEquals(Batch(3, 5, 2, 4, 1, 3, 2, 10).distinct, Batch(3, 5, 2, 4, 1, 10)) + } + + test("distinctBy") { + // Takes the first odd and event number it finds. + assertEquals(Batch(3, 5, 2, 4).distinctBy(_ % 2), Batch(3, 2)) + } + }