<@UG5HTPZ54> Natural transformations are defined a...
# arrow
p
@Paolo Gavočanov Natural transformations are defined as FunctionK in Arrow
p
yes, got that, I implemented the first example
but I guess the For and Of stuff gets me confused
is just much more straight forward to figure-out the signatures in scala/haskell for me ATM then in Arrow
toying around with something like this, but gets me nowhere near atm 😕
Copy code
object ImmutableKV : FunctionK<ForKVStore, ForState> {
        override fun <A> invoke(fa: Kind<ForKVStore, A>): Kind<ForState, A> {
            val op = fa.fix()
            return when (op) {
                is Put<*> -> StateApi.modify { mapK: MapK<String, Any?> -> mapK.updated(op.key, op.value) }
                is Get -> StateApi.inspect { mapK: MapK<String, Any?> -> mapK[op.key] as A }
                is Delete -> StateApi.modify { mapK: MapK<String, Any?> -> (mapK - op.key).k() }
            } as State<MapK<String, Any?>, A>
        }
p
see if you can find the way around there. I cannot be more useful right now, I'm in another office working 😄
p
np, thnx a lot for the direction 😉
r
ank no longer uses Free
p
hey @raulraja, thnx for the pointer, been there, did my
Id
and
Eq
, having trouble with
State
, and I guess later on (from the cats article) with
Inject
.
https://typelevel.org/cats/datatypes/freemonad.html#composing-free-monads-adts is where it gets interesting IMO with free monads, and that’s not covered by tests or docs in Arrow ATM, I guess it would be nice to add some docs/samples to Arrow once I figure it out.
r
We have never bothered to get free and inject working because it would require injections manually since there is no implicits in Kotlin but keep87 would solve this
Also inject +free is not a good idea since it degrades in performance as the number of algebras increases and requires special runtime optimizations like the ones we do in Scala
I would not recommend Free for architecture in Kotlin, just as.inyernal stack safe machinery or very simple programs
p
yes, agree, I saw there is no
FlatMapped
and co. in Arrow, so all in all not ready for prime time in Kotlin, better do exploration in Scala ro Haskell thnx a lot for your time guys!
r
You can find the code in Scala and Haskell here too https://gist.github.com/raulraja/13a8a8789f9b70a1535ea4d44dfb1777
in case it is of any help in your exploration around Free