These are chat archives for typelevel/cats

30th
Apr 2018
Florin Bunau
@fbunau
Apr 30 09:59
does anyone know if there is such a thing as transforming a Map[K, F[A]] to F[Map[K, A]] ? ... ermm like a weird sequence on the map ?
Luka Jacobowitz
@LukaJCB
Apr 30 10:00
If that Map is a SortedMap that should in fact just be .sequence
Otherwise you can use unorderedSequence which will require commutativity
Fabio Labella
@SystemFw
Apr 30 10:02
or import alleycats.std._ and do sequence
Luka Jacobowitz
@LukaJCB
Apr 30 10:02
Or that :smile:
Fabio Labella
@SystemFw
Apr 30 10:07
that's only safe if your Map preserves order
which is the case if you only use the std implementation
but we can't provide that instance in normal cats because we can't guarantee that
Florin Bunau
@fbunau
Apr 30 10:09
indeed it is a SortedMap, thanks for the tip, wonder why I haven't just tried it, still wrangling the types
Luka Jacobowitz
@LukaJCB
Apr 30 10:10
If it doesn’t work, check if partial-unification is turned on :smile:
Florin Bunau
@fbunau
Apr 30 11:23
@LukaJCB gave up to try to make it work in my big project, so I wrote a smaller snippet
import cats.Applicative
import cats.effect.IO
import cats.syntax.traverse._

import scala.collection.SortedMap

object SequenceExample {

  def main(args: Array[String]): Unit = {

    compute[IO].sequence

  }

  def compute[F[_]: Applicative]: SortedMap[String, F[Int]] = {
    SortedMap(
      "a" -> Applicative[F].pure(1),
      "b" -> Applicative[F].pure(2),
      "c" -> Applicative[F].pure(3)
    )
  }

}
still can't make it compile
Fabio Labella
@SystemFw
Apr 30 11:25
What's the error
nigredo-tori
@nigredo-tori
Apr 30 11:25
import cats.implicits._?
Fabio Labella
@SystemFw
Apr 30 11:25
Ah
Yes
And remove the syntax import
Or
Keep syntax import but add the instances import for maps
Florin Bunau
@fbunau
Apr 30 11:27
still Error:(12, 17) value sequence is not a member of scala.collection.SortedMap[String,cats.effect.IO[Int]] compute[IO].sequence
Oleg Pyzhcov
@oleg-py
Apr 30 11:28
You should use scala.collection.immutable.SortedMap, not scala.collection.SortedMap
Luka Jacobowitz
@LukaJCB
Apr 30 11:29
:+1:
Oleg Pyzhcov
@oleg-py
Apr 30 11:31
and
Florin Bunau
@fbunau
Apr 30 11:31
@oleg-py wow, that was it
Oleg Pyzhcov
@oleg-py
Apr 30 11:31
you'd also need cats.instances.string._, since Traverse requires a cats.Order on keys
if you're not using mega import
Florin Bunau
@fbunau
Apr 30 11:33
cool, thanks for the help guys now it works, amazing advice
I kept checking everything :)) didn't even know SortedMap is not immutable and you need some other SortedMap,import dialogue is dangerous
Mark Tomko
@mtomko
Apr 30 17:41
We've got a moderately large codebase that's still on cats 0.9. My coworkers are hesitant to update to 1.X because of the deprecation of .traverseU and its ilk, since IntelliJ has a hard time with plain .traverse. I know many of you aren't using IntelliJ, but those of you who are, do you have strategies for dealing with cases where IntelliJ isn't up to the task?
Jose C
@jmcardon
Apr 30 17:42
@mtomko I basically bite the redlines
Luka Jacobowitz
@LukaJCB
Apr 30 17:42
Annoy the intellij team to fix it
Jose C
@jmcardon
Apr 30 17:43
I mean, worst case, I try to annotate types or some other solution so it doesn't interrupt everything else I'm doing
Mark Tomko
@mtomko
Apr 30 17:43
@LukaJCB I'll try and find my IntelliJ account and try to bug them about it, and recruit help from my coworkers.
Jose C
@jmcardon
Apr 30 17:43
like i.e
Jose C
@jmcardon
Apr 30 17:44
val r: F[Int] = (fa, fb).mapN(_ +_)
//do stuff with r
^ or that
whenever something is redlined I try to annotate types and continue, worst case
I used to have to do that a lot with the doobie interpolator since it was always redlined before. Thankfully they fixed it
Mark Tomko
@mtomko
Apr 30 17:48
I'll play with some type annotations. In this case, it doesn't seem to help (sorry for the long type signature):
val secondaryIndexes: ValidatedNel[String, (Map[String, Gene], Map[String, Transcript[Gene]])] = 
  (vf, vgi, vti).mapN { case (_, genesBySymbol, transByAccession) => 
    (genesBySymbol, transByAccession)
}
That's not the .traverse case, I haven't tried annotating one of those a little more carefully.
Mark Tomko
@mtomko
Apr 30 17:54
I guess in that case I could use an Apply[ValidatedNel[String, ?]].map3, in similar cases that seems to avoid the problem.
Mark Tomko
@mtomko
Apr 30 18:03
It probably makes sense for people to pick a few key issues on IntelliJ's bugtracker and focus voting there. Here's one for mapN: https://youtrack.jetbrains.com/issue/SCL-12892
For unification in general https://youtrack.jetbrains.com/issue/SCL-11320, but they suggest there that a fix might be coming in 2018.1, which is what we're using now I think... oh well.
Thanks everyone.