These are chat archives for typelevel/cats
Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
pureEvalas well as a by-name
pointlike in Scalaz due to sketchy effect-capture usage?
IO(or some other data type)
MonadRecbut was also unable to offer a straightforward example.
IO) but in our world there are a handful. Abstracting over this operation is super sketchy and needs to be done with great care, not with an innocuous looking thing like
Hi! Sorry to disturb, I have a question regarding
Foldable.foldK. I'm going through the exercises at
https://www.scala-exercises.org/cats/foldable and there is this one line:
Foldable[List].foldK(List(None, Option("two"), Option("three"))) should be(Option("two"))
What confuses me is that if we use a Monoid instance to combine the elements, the result would be
Option("twothree"). Why does
Option("three") from the combination?
MonoidKdoes not rely on there being a
Monoidfor the contained type and therefore implements the combine/append as just taking the second parameter as result.
Some[A]if you know how to combine two
Aaka you have a
Semigroupfor them. If you have that you also have a
Monoid[Option[A]]If you do not have that you have to take one or the other which may or may not be helpful for what you want to do. The "why?" is explained here a bit: https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/MonoidK.scala#L15
def combine[A](x: Option[A], y: Option[A]): Option[A]. Since it has to work for all
A, you don’t have access to a
Semigroup[A]. Therefore you really only have a few possible implementattions
Some(if there is one). There are a couple other possibilities.
i'm looking into Validated, ValidatedNel, etc. Say I have the following two functions:
def getItems(id:String) : List[Item] def getDetails(code:Int) : ItemDetail
where Item has a field called code. Any of the two can throw an exception. I'm looking for a way to fetch the items for an id, and then the details for those items, and accumulate all the errors. Validated sounds like a way to do this (though the first has to work for the following n queries to happen). I'm having trouble finding a nice way of doing this. Would appreciate any suggestions.
ItemDetailfor the ones that succeeded?