Randall Perry
09/22/2021, 6:02 PMfun <A> sequence(fs: FList<Rand<A>>): Rand<FList<A>> = { rng ->
when (fs) {
is FList.Nil -> unit(FList.empty<A>())(rng)
is FList.Cons -> {
val (a, nrng) = fs.head(rng)
val (xa, frng) = sequence(fs.tail)(nrng)
FList.Cons(a, xa) to frng
}
}
}
This 1st answer was said to be not stack-safe, and the correct solution uses foldRight.
But, I’m trying to understand the syntax. They have the ‘rng’ or the ‘nrng’ var enclosed in parantheses following the two return values:
unit(FList.empty<A>())(rng)
sequence(fs.tail)(nrng)
What does this mean? Is invoke being called via the parantheses? Or is the RNG type getting passed thru?julian
10/03/2021, 12:53 AMsequence
returns a lambda. So sequence(...)(...)
calls sequence
and executes the lambda returned by sequence
. @Randall PerryRandall Perry
10/10/2021, 4:35 PMjulian
10/10/2021, 6:27 PM