Hello, I just started to use arrow and I have some...
# arrow
r
Hello, I just started to use arrow and I have some problems with the following code based and the validated example. I got this nicely working with the either monad (without the Rules class) but I would like to understand how to get rid of the fix and flatMap calls here and how to make this work for the accumulate strategy. Since validated is just a monoid flatMap would be not an option in that case, right ?
Copy code
fun validate(
   p: Player,
   i: Idea.OpenIdea,
   members: Eval<NonEmptyList<Member>>
): Either<NonEmptyList<ValidationError>, UnvalidatedPlayer> {
   return (Rules failFast {
       UnvalidatedPlayer(p, i)
           .let {
               it.accountNotLocked(TeamDbRepository)
                   .flatMap { it.notMember().fix() }
                   .flatMap { it.hasEnoughSkills().fix() }
                   .flatMap { it.notTooManyUnfinishedIdeas().fix() }
                   .flatMap { it.budgetLimitNotReached().fix() }
                   .flatMap { it.suitableDepartment(TeamDbRepository).fix() }
                   .flatMap { it.skillsInLimit(members, TeamDbRepository).fix() }
                   .flatMap { it.teamNotComplete(members).fix() }
                    .flatMap { it.cantAddAgain(PlayerRepository).fix() }
           }
   })
}
r
hi @Roger Gilliar, the example with Applicative error and therefore Rules encoded with Kinds will go away and instead adapted to be concrete over Either and Validated. Kinds and their type classes will be deprecated in 0.12 and removed in 0.13; 0.12 is around the corner just a few more weeks as we tidy up the release.
🚀 1
😀 1
As a workaround you can replace the encoding of the applicative error for Either directly in which its concrete flatMap should not require you call
fix()
I’ll be working on docs for arrow core this week and I’m hoping to tackle those examples and adapt them to the new encoding.
r
Thanks for the fast reply. I'm glad that Kind will go away ....
👍 1
j
😆 I'm not glad that Kind is going away! I was so proud of myself for finally being able to understand and use it. I'll never get those neurons back now! And how will I prove to non-functional programmers that I'm so smart?
🤣 4
g
@raulraja so what's the future of HKT in Arrow? They are going to be deprecated completely or will have a different implementation (not through Kind...)?
s
Hei @raulraja How would
Validated
with applicative look like ? I use it a lot as I can collect errors in parallel like :
Copy code
Validated
  .applicative(NonEmptyList.semigroup<MyError>())
  .mapN(...) { (a, b, c) -> ... }
  .fix()
BTW, it is nice as Kinds are not inlined and also don’t have
suspend
, so doesn’t mix well with effectful methods and apis from arrow like
Either.catch { … }
r
@Satyam Agarwal it would look like:
Copy code
val result =
  ValidatedNel.mapN(
    Semigroup.nonEmptyList(),
    1.validNel(),
    MyError.invalidNel(),
    1.validNel()
  ) { a, b, c ->
    ...
  }
mapN
here is also inlined so it will work across suspension as well.
👍 2
c
@raulraja to see if I got your comment above,
1.0
will be released without Higher Kinds, is there any examples to what the alternative will be? Also any timeline projections for
0.12
and
1.0
? Many thanks and keep up the good work
r
hi @Carlos Fernandes, Arrow 0.12 and 0.13 will come out in a few weeks, we are finishing up the last bits. 0.12 will come with kinds deprecated and some replacements that can be applied but in general if you can go straight to 0.13 that would be easier. From 0.13 and forward there is no kinds and it’s all based on suspension or regular concrete functions.
after 0.13 which has the encoding for 1.0 there may be a couple of milestone releases but other than that from there on will be the 1.x series
❤️ 1
😍 1
i
Quick (maybe) question: About HKT being deprecated, @raulraja says
fix()
is going away, and to use something like:
Copy code
val result =
  ValidatedNel.mapN(
    Semigroup.nonEmptyList(),
    1.validNel(),
    MyError.invalidNel(),
    1.validNel()
  ) { a, b, c ->
    ...
  }
…but
ValidatedNel.mapN
is an unresolved reference for me, using
0.11.0
. Is this something new in 0.12.0-SNAPSHOT? Implied user code I’m too slow to infer? (Disclaimer: I’m enough of an Arrow newbie that @Satyam Agarwal’s example made sense, but @raulraja’s is utterly impenetrable to me.) (I’m working my way through https://medium.com/google-developer-experts/advanced-fp-for-the-enterprise-bee-kleisli-1d0de0fa82d9 and https://www.manning.com/books/functional-programming-in-kotlin in the little downtime I’ve got, fwiw.)
r
@ibcoleman
mapN
appears on the companion of validated in 0.12.0 which will be released sometime in the following weeks. Prior to 0.12.0 mapN should be available as an extension import for the
validated
extensions
👍 1