Is there any way to use one arb's result to feed t...
# kotest
d
Is there any way to use one arb's result to feed the function params for another arb and make a pair out of them (arb1, arb2 cartesian product)?
s
map ?
d
In map there's no RandomSource
s
hmmm true
d
And it'll only produce one arb2 per arb1
s
map could return a pair, but yeah no RS
d
I need a set of Arb2's for each Arb1, and end up with Pair<Arb1, Arb2> as a cartesian product
s
then what are you doing with the pair
d
using it in checkAll to run the tests
s
so you want to do checkAll(arb1, arb2) { a, b -> }
d
There's a Context object for setting up the repositories and the useCase, and there's a Request object that needs to be set up based on the Context but in many permutations...
yes
s
Copy code
checkAll(arb1) { a ->
  checkAll(Arb2(a)) { b ->
  }
}
d
Oh... I see
s
will that do what you want ?
d
I guess that would do it... but there's nothing to check in the outer checkAll... 🙃
s
doesn't matter, you're just nesting
d
Ok, I guess that'll do, thanks!
s
cool
m
@dave08 you may be interested in
Arb<A>.flatMap(fn: (A) -> Arb<B>): Arb<B>
d
I don't think that has a RandomSource either...
Actually... maybe I wouldn't need one there?
m
If you need access to rs you can do
Copy code
arb.flatMap { a -> arbitrary { rs -> ... } }
🤩 1
Under the hood kotest will propagate that from the time data is generated from the arb so it's better than nesting check all
👍🏻 1
d
That could be a good idea! I'll give it a try, thanks!
Actually, in my current case it's much simpler than I thought:
Copy code
val contextWithRequestArb = contextArb.flatMap { context ->
        requestArb(context.currState).map { request ->
                context to request
        }
    }
But sometimes that rs is needed, so it's good to know that trick too!
m
Awesome!