so I want the kotlin version of declaring an `impl...
# arrow
s
so I want the kotlin version of declaring an
implicit Fibble[T]
s
There is no such thing as
implicit
in Kotlin, this is why all typeclass constraints are regular parameters. Hopefully with KEEP-87 that would change, more on KEEP-87 here https://github.com/Kotlin/KEEP/pull/87.
s
Yep I've been following 87
s
What signature would
Fibble
have? And what is your use-case?
s
what I'm asking is, what's the arrow teams best advice
Copy code
sealed class Foo {
   object A : Foo()
   object B: Foo()
}
interface MyTypeclass<T> { fun doit(t : T) }
typeClassInstance.doit(someT)
s
How does the typeclass relate to the ADT?
s
The real domain is I have some errors represented by an ADT say called
Error
and in a particular case I want to marshall these errors back over HTTP. So I want a typeclass
HandleError
or whatever I call it, and move the logic for
SubscriptionInvalidError
or whatever errors I have handled per typeclass.
s
Any reason you don’t want to use
when
?
s
not really, just end up with a massive switch
when
is what I'm doing atm
s
You can split the methods even across files if you want
We do this in Arrow as well, and we’ll do that more in the future.
s
I can do
when (t) { is SubscriptionInvalidError -> SubscriptionInvalidErrorHandler.doit(t) }
s
There is a couple of tricks you can do
s
ok
I won't know the static type of course, I just have a subclass of T. So it wouldn't even work with scala's implicits.
s
Give me a sec 😜
s
😂
s
typeclasses won’t help you there either. There needs to be a boilerplaty when somewhere
But I am trying something else not sure if it’s valid Kotlin 😂
s
🙂
I suspected the answer might be "stick with when"
s
Nevermind, doesn’t work. You can annotate your ADT with
@autofold
if you use
arrow-meta
, move the methods to seperate files.
Copy code
//DoItA.kt
fun DoItA(a: A)
//DoItB.kt
fun DoItB(b: B)

//ADT.kt
@autofold sealed class Foo {
   fun doIt() = fold(::DoItA, ::DoItB)
   object A : Foo()
   object B: Foo()
}
That’ll be about as good as it gets I think
s
fold will do teh when for you ?
s
yep
s
clever
s
it’s inlined 2
s
do you need to use kapt or anything
s
yes for
@autofold
s
ok let me read about it
s
It just adds a single
fold
method as an extension function to your ADT.
s
right
s
inside is just a
when
.
s
simple
s
Anyway I hope I was of some help.
s
Absolutely
You always are
Any docs on @autofold btw ?
s
Ouch, I skimmed on those 😄 Feel free to add something if you want, I never gave it enough attention after I wrote it.
So much work to do ^^
s
ok
Can you link me to a project that uses autofold ?
that should be enough for me to set it up
s
👍🏻
s
It's the same setup for all meta programming.
s
ty
s
You're welcome