Ville Peurala
09/21/2022, 6:44 AMsimon.vergauwen
09/21/2022, 6:55 AMVille Peurala
09/21/2022, 6:56 AMsimon.vergauwen
09/21/2022, 6:57 AMsimon.vergauwen
09/21/2022, 6:57 AMVille Peurala
09/21/2022, 7:01 AM```interface Timed<A> {
fun result(): A
fun startMs(): Long
fun endMs(): Long
}```Now I would like to make
Timed
a Functor so that users could always map overt the result without affecting the timings.Ville Peurala
09/21/2022, 7:03 AMfun <B> map(fn: (A) -> B): Timed<B>
to my interface but I have the feeling that it is not an optimal solution.simon.vergauwen
09/21/2022, 7:04 AMbind
or flatMap
. Since in Kotlin we don't have a need for Functor
for collections.
I.e. you can do list.map { either.bind() }
safely within a DSL to replace traverse 🎉
So in this case I would opt for adding map
, or I think you would need to define zip or Applicative
as well and then you can also implement Monad
.simon.vergauwen
09/21/2022, 7:05 AMstartMs
and endMs
does it take the earliest startMs
and the latest endMs
? 🤔simon.vergauwen
09/21/2022, 7:05 AMmap
function.simon.vergauwen
09/21/2022, 7:06 AMinline
you will be able to call suspend
functions from the lambda, but you'll need to write map
as an extension function on Timed<A>
since inline
functions need to be final
😉Ville Peurala
09/21/2022, 7:07 AMTimed<A>
would need some thinking about, but I'm not sure yet whether I need it. I might need a Monad too, but I'll start with a Functor now and see where that takes me.simon.vergauwen
09/21/2022, 7:17 AMsimon.vergauwen
09/21/2022, 7:18 AMtimed { transform(timedA.bind(), timedB.bind(), timedC.bind(), ...) }
and the strategy it applies over combining startMs
and endMs
is parameterised.simon.vergauwen
09/21/2022, 7:19 AMVille Peurala
09/21/2022, 7:20 AM