Skip to content

Commit

Permalink
Fixed PurpleKingdomGames#639: Batch distinct and distinctBy
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 26, 2023
1 parent 1c62788 commit be94b73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}

0 comments on commit be94b73

Please sign in to comment.