When using Arrow with Android, how would one pass ...
# arrow
j
When using Arrow with Android, how would one pass an instance like Either via an Intent, since Intent requires the Either to be Serializable or Parcelable?
I guess I could write a custom Parceler...
But I think there may be no generic way to do so...
Not great. There's that extra level of wrapping 😞
s
Hey Julian, It's not really possible to make
Either
implement
Serializable
or certainly not
Parcelable
with the reason being that we'd need to constraint
A
and
B
to also be
Serializable
. (and
Parcelable
requires a dependency on Android).
I think the easiest approach here is to save
TempItemId
and
PermItemId
into
Intent
by unwrapping it from
Either
using
fold
or
when
and to wrap it again when you extract it from the
Intent
s
What would be the use case where you have things that are not serializable as values inside either?
s
Oh, seems I was mistaken πŸ˜… It's just an empty
interface Serializable
with no methods. I thought it was like
interface Comparable
which requires you to restrict
A
and
B
to be
A : Comparable
and
B : Comparable
in order to correctly implement
compareTo
.
However, Effective Java recommends to never implement
Serializable
unless you need to inter-opt with legacy systems. Making
Either
Serializable
for putting it in an
Intent
seems backwards since on Android
Parcelable
is definitely the way to go and not
Serializable
.
πŸ‘ 3
s
so you are saying Android is a legacy system 🧌
πŸ˜… 4
πŸ’― 3
j
Okay, thanks @stojan, @simon.vergauwen.
It was a bug πŸ˜‚πŸ˜‚πŸ˜‚
πŸ€¦β€β™‚οΈ 1