Hi! I’m currently using TupledFunction in scalamock like this:
extension [F](inline f: F)
/**
* Allows to get caught method arguments.
* For multiple arguments - returns them tupled.
* One list item per call.
* {{{
* trait Foo:
* def foo2(x: Int, y: Int): Int
*
* val foo = stub[Foo]
*
* foo.foo2.returns(_ => 1)
*
* foo.foo2(0, 0)
* foo.foo2(1, 1)
*
* foo.foo2.calls // List((0, 0), (1, 1))
* }}}
*/
inline def calls[Args <: NonEmptyTuple, R](
using TupledFunction[F, Args => R]
): List[UntupledOne[Args]] = ???
type UntupledOne[X <: NonEmptyTuple] = X match
case head *: EmptyTuple => head
case _ => X
And I wonder if there is any possibility it can be improved to work with NamedTuple like this:
type NonEmptyNamedTuple = ???
extension [F](inline f: F)
/**
* same as before
* {{{
* foo.foo2.calls // List((x = 0, y = 0), (x = 1, y = 1))
* }}}
*/
inline def calls[Args <: NonEmptyNamedTuple, R](
using TupledFunction[F, Args => R]
): List[UntupledOne[Args]] = ???
type UntupledOne[X <: NonEmptyNamedTuple] = NonEmptyTuple.DropNames[X] match
case head *: EmptyTuple => head
case _ => X