Any idea on how to implement the following function in Scala 3?
I am okay with inline
or not, and generally, a slight syntax change is ok (even macros are fine).
But I don't know how to do this without asInstanceOf
.
type Pred[A] = A => Boolean
/** Computes values of predicates and combines them with `&&`.
*
* The implementation does not use `asInstanceOf` or `isInstanceOf` */
inline def tupled[Args <: Tuple](inline preds: Tuple.Map[Args,Pred], inline args: Args): Boolean
Example:
val pred: (Int => Boolean, Int => Boolean) = (_ < 0, _ > 0)
println(tupled[(Int, Int)](pred)( 1, 2)) // should print false
println(tupled[(Int, Int)](pred)(-1, 2)) // should print true
How about this one:
And we can ignore the type parameter if swap the arguments: