Hi. I have couple of questions, mostly about "why ...
# arrow
a
Hi. I have couple of questions, mostly about "why something exists" and "why something is written that way" • Is there any use for
Const
assuming we don't have HKT simulation anymore? • Same question for
widen
(code examples seems to be working just fine without
widen
call) • Is there a reason to implement most functions inside of Either/Validated/etc or is it just the matter of preference? (I think standard library usually extract non-essential functions as extensions as much as it's possible considering interop) • Is there any code examples about using Arrow with any popular framework/library like Ktor or Spring? • What's the usage of
Endo
? (didn't really find it in the repo)
s
Hey @Alexander Levin, Thanks for these good question! • Const is still being used in some niche use-cases. You can use it for type tagging for example. `````` `
Actually I refactored
Const
away in Arrow, so this data type is probably the most likely to be up for deprecation towards 2.0. It’s possible to use
Const
, for type tagging but there are other concrete options that typically for fine in most occasions.
widen
is still useful to upcast the type.
Copy code
Either<Error, Int> -> Either<Error, Number>
Implementing functions as methods is always more desire-able. They don’t need explicit imports, and they’re slightly faster than static invokes.
functions for
Either
that are implemented as extension functions is because the generics are defined as
out
, and we need to re-capture the generic to ignore the
out
restriction.
There are some examples out there, but nothing official. I’m working on something since after the 1.0.0 release, I’ll probably share it next month after my PTO.
Endo
is a type meant for
Monoid
to compose functions.
a
@simon.vergauwen Hi, thanks for answers!
widen
 is still useful to upcast the type.
Either<Error, Int> -> Either<Error, Number>
Maybe I am missing something but looks like it works out of the box without
widen
call:
Copy code
val either: Either<Error, Int> = Either.Right(123)
val widened: Either<Error, Number> = either
s
Copy code
fold(either.widen<Number>()) { acc, n -> }
Here is a case where you need
widen
, but I must admit the cases are very rare. In some cases they can indeed also we replaced by explicitly recapturing in a
val
with a different type. That’s also the implementation of the
widen
function.