Alexander Schell
08/25/2020, 8:13 AMsimon.vergauwen
08/25/2020, 8:18 AMDate
but you need to work with Long
but you know how to map Date -> Long
and map back Long -> Date
then you can use Invariant
to apply that logic over Date
. Given that they're nested inside Either
, or Validated
etc.Alexander Schell
08/25/2020, 8:22 AMAlexander Schell
08/25/2020, 8:22 AMsimon.vergauwen
08/25/2020, 8:26 AMIO
into suspend
with Arrow Fx Coroutines.
We're removing things that don't make a lot of sense, like Option
which is only necessary in certain generic code but not so relevant in user code, etc.
But Cats was originally inspired from ScalaZ to make more sense in Scala, which was a port from the Haskell standard library.
All these concepts in functional programming are the same, but it's a balance of what works best in certain languages/VMs etc.Alexander Schell
08/25/2020, 8:28 AMthan_
08/25/2020, 11:42 AMthan_
08/25/2020, 11:42 AMdef longToDate: Long => Date = new Date(_)
def dateToLong: Date => Long = _.getTime
implicit val semigroupDate: Semigroup[Date] =
Semigroup[Long].imap(longToDate)(dateToLong)
val today: Date = longToDate(1449088684104l)
val timeLeft: Date = longToDate(1900918893l)
simon.vergauwen
08/25/2020, 12:01 PMInvariant
instance for Monoid
, it seems there isn't one for Semigroup
. Sadly it requires higher kinds to do this.
https://github.com/arrow-kt/arrow-core/blob/master/arrow-core/src/main/kotlin/arrow/core/extensions/MonoidInvariant.ktsimon.vergauwen
08/25/2020, 12:01 PMMonoid.long().imap(longToDate, dateToLong)
and get back Monoid<Date>
.than_
08/25/2020, 12:06 PMForSemigroup
that threw me off.than_
08/25/2020, 12:06 PMAlexander Schell
08/26/2020, 11:30 AMsimon.vergauwen
08/26/2020, 11:30 AMF
Alexander Schell
08/26/2020, 11:31 AMsimon.vergauwen
08/26/2020, 11:33 AMF
for Invariant
there is Monoid
, but it could just as well be Either
or etcsimon.vergauwen
08/26/2020, 11:33 AMIso
Alexander Schell
08/26/2020, 11:43 AM