Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
nafg
@nafg
You definitely should, scala needs more :)
Rob Norris
@tpolecat
Huh, no I haven't seen that.
nafg
@nafg
haven't used it, but it's by the author of the Splain compiler plugin and I was browsing his repos
Rob Norris
@tpolecat
Looks interesting. Edmund is writing one too.
nafg
@nafg
Is that why he's been so silent on Gitter lately? :D
Rob Norris
@tpolecat
He quit most of typelevel and scala/scala so he's less visible.
nafg
@nafg
:(
Michael Pilquist
@mpilquist

Maybe I should start a podcast.

@tpolecat: Yes!

nafg
@nafg
At a minimum, you could do an episode on @agbell's https://corecursive.com/
The entire episode could be about testing gripes :laughing:
Rob Norris
@tpolecat
I got an email from him a few hours ago, reminding me that I never responded to his email from a month ago.
But yes, I should do that.
Harmeet Singh(Taara)
@harmeetsingh0013
Hey channel, I am new to scala-cats, I have one quick question, why we require Foldable even scala core collections have method fold, foldLeft and foldRight?
Loránd Szakács
@lorandszakacs

folks, if my main "method" is ultimately described as a Task[Unit] it is a sane thing to just mainTask.runSyncUnsafe(Duration.Inf), at the end of the world right? Or is there a better way of running your final app?

Until recently I had cats.effect.IO, but for various reasons wound up changing it to monix Task, and w/ IO I just did the mainIO.unsafeRunSync — worked fine.

Adelbert Chang
@adelbertc
yeah
you generally want to just do it once at the "end of the world"
which is main
Luka Jacobowitz
@LukaJCB
@harmeetsingh0013 can you rephrase your question? I'm not sure I understand (:
Matthias Sperl
@m-sp
@lorandszakacs If you are already using monix you might just use the TaskApp as well?
Loránd Szakács
@lorandszakacs
@m-sp because I didn't notice it before :D perfect, thank you!
Harmeet Singh(Taara)
@harmeetsingh0013
@LukaJCB according to Foldable, it helps us to use list of monoids into single value, but we have also achive this, by scala foldLeft, fold and foldRight functions, why we should use scala-cats Foldable rather than core scala library fold?
Luka Jacobowitz
@LukaJCB
Monoids are a lot more composable than foldLeft for one
Also Foldable allows you to use abstract types instead of specifying a specific Scala collection itself
Harmeet Singh(Taara)
@harmeetsingh0013
@LukaJCB thanks, If possible, can you give any example on this "Monoids are a lot more composable than foldLeft for one"?
Luka Jacobowitz
@LukaJCB
Right sure
So for example a tuple of two monoids is also a monoid
An either of two monoids is also a monoid
A function returning a monoid is also a monoid
An option containing a monoid is also a monoid
Fabio Labella
@SystemFw
@harmeetsingh0013 nice example, groupBy
in stdlib is weird
foldMap(t => Map(t.k -> List(t.v)))
beautiful
imagine t beingUser(k: Age, v: Name)
Luka Jacobowitz
@LukaJCB
Yup!
Harmeet Singh(Taara)
@harmeetsingh0013
Thanks @SystemFw , but foldMap is not used with monoids, if i am not worng?
Fabio Labella
@SystemFw
you are :)
Harmeet Singh(Taara)
@harmeetsingh0013
@LukaJCB If possible, can you please give code snippet?
Fabio Labella
@SystemFw
foldMap[F[_]: Foldable, A, B: Monoid](fa: F[A])(f: A => B): B
Harmeet Singh(Taara)
@harmeetsingh0013
@SystemFw :P
Luka Jacobowitz
@LukaJCB
There are some great examples here https://typelevel.org/cats/typeclasses/monoid.html
Fabio Labella
@SystemFw
@harmeetsingh0013 bigger example
you have this case class Students(name: String, classID: String)
and you have List[Student]
and you want Map[String, (Int, List[Student])]
so map from Class (in a school sense) to the corresponding students. The Int is the number of students in each class
try with stdlib first, and I'll show you the Monoid solution (that uses compositionality)
Harmeet Singh(Taara)
@harmeetsingh0013
Ohhh great @SystemFw , I will try to create using stdlib
Han van Venrooij
@irundaia

I've been doing the scala exercises on cats. I've been surprised by the following example on Semigroups (note that this example has been paraphrased):

import cats.implicits._

val f1 = (x: Int) => x + 1
val f2 = (x: Int) => x * 10

val f3 = f1 |+| f2

println(f3(6)) // prints 67

I would have expected that composing of twoFunction1s would compose those functions if applicable. Were that the case I would have expected the result to be 70.

Where could I find out how the Semigroup instance for Function1 is defined? I tried looking at the cats-core code. But I couldn't find out where the Semigroup/Monoid instance is defined :(