Compare commits

...
Author SHA1 Message Date
admin 731d8a72ad Remove FunctionalRandom asInstanceOf casts 2026-06-20 15:59:58 -07:00
@@ -1,6 +1,6 @@
package net.eagle0.common
import scala.annotation.{nowarn, tailrec}
import scala.annotation.tailrec
import scala.collection.SeqFactory
case class RandomState[+T](
@@ -160,10 +160,9 @@ abstract class FunctionalRandom {
)(
f: (T, FunctionalRandom) => RandomState[S[U]]
)(using xFactory: FACT): RandomState[S[U]] = {
@nowarn def foldGen(rsU: RandomState[S[U]], t: T): RandomState[S[U]] =
rsU.continue {
case (us: S[U], fr: FunctionalRandom) =>
f(t, fr).map(x => (us ++ x).asInstanceOf[S[U]])
def foldGen(rsU: RandomState[S[U]], t: T): RandomState[S[U]] =
rsU.continue { (us, fr) =>
f(t, fr).map(x => xFactory.from(us ++ x))
}
FunctionalRandom.nextFoldLeft(
seq,
@@ -179,17 +178,16 @@ abstract class FunctionalRandom {
nextFlatMapImpl[T, U, Vector, SeqFactory[Vector]](vec)(f)(using Vector)
private def nextMapImpl[T, U, S[X] <: Seq[X], FACT <: SeqFactory[S]](
seq: Vector[T]
seq: S[T]
)(
f: (T, FunctionalRandom) => RandomState[U]
)(using xFactory: FACT): RandomState[S[U]] = {
@nowarn def foldGen(
def foldGen(
rsU: RandomState[S[U]],
t: T
): RandomState[S[U]] =
rsU.continue {
case (us: S[U], fr: FunctionalRandom) =>
f(t, fr).map(x => (us :+ x).asInstanceOf[S[U]])
rsU.continue { (us, fr) =>
f(t, fr).map(x => xFactory.from(us :+ x))
}
FunctionalRandom.nextFoldLeft(seq, RandomState(xFactory.empty[U], this))(