Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Soren
@srnb_gitlab
Where can I find one
Matthias Berndt
@mberndt123
Are there any type class instances for PartialFunction in cats?
It's an obvious candidate for some type classes, e. g. Category[PartialFunction], but I've imported cats.implicits._ and it just doesn't seem to be there. Any reason why?
Sven Ludwig
@iosven
What happened to sequenceU?
My problem I need to solve: I have a Seq[ValidatedNel[ValidationError, FrequencyDisplayConfiguration]] and need to convert it to ValidatedNel[ValidationError, Seq[FrequencyDisplayConfiguration]]. (In my case the given Seq is never empty.)
Fabio Labella
@SystemFw
you need to use a concrete type like List or Vector
then just sequence
Sven Ludwig
@iosven
thanks
Henry Story
@bblfish
@luis3m I used your Pairing code that came from "Comonads for UIs” and managed to use it to translate the code in that thesis here Simple Console App and here ComonadConsoleApp, so up to the end of chapter 3.
That was really helpful.
Luis Martinez
@luis3m
cool stuff, I'll take a look on the blog post :)
Wojtek Pituła
@Krever
Is there something like attempt but for subset of E ? I would like to catch only specific subtypes of my error into Either. Other then map+asRight+recover of course
Gabriel Volpe
@gvolpe
You can have that if you have an ApplicativeError[F[_], E] @Krever
If you're working with the default instance with the error type fixed as Throwable you're out of luck. You could make it work if E <: Throwable by deriving the ApplicativeError[F[_], E] using classy prisms.
Gavin Bisesi
@Daenyth
I'd write an attemptSome combinator probably
with PartialFunction[E, F[A]] I guess
or => Either[E, A]
matfournier
@matfournier
Am I going down the wrong path here? I have requests coming in and I want to attach some metadata (a few keys describing the breadcrumb path I've gone down). I'm not using Writer for logging, but I'm wanting to use it for a few short lived requests for this. Problem being if something throws inside of Writer, I lose that breadcrumb path I'm most interested in --I guess writer is not a MonadError? Is my only option some sort of thread local storage and then bumping it across async boundaries (e.g. a propagating LogContext in uhh, slf4j terms).
Andi Miller
@andimiller
you can do that with StateT
Gavin Bisesi
@Daenyth
not concurrently
Also ThreadLocal is a no-go if you're on IO
@matfournier I think the easiest way is to add a Context[F] input where Context is a trait that defines the api you want for recording this information
matfournier
@matfournier
My entire flow is sequential, though sometimes my state updates would be stuck inside an F (e.g. Task). But I'd never have Tasks in parallel trying to write anything.
Andi Miller
@andimiller
the StateT approach only gives you Sync
but it means you have your state when you're in raiseError
matfournier
@matfournier
That might be enough.
I did it like that, warning, probably a terrible idea
matfournier
@matfournier
Hah
I mean, the code I've inherited does this with a mutable global that is cleared on every request, so anything is an improvement.
Gavin Bisesi
@Daenyth
I think the Context approach is nice because it's quite explicit and obvious
you could also put it in, wrapping the global you currently have, and then change the behavior just by passing in one that isn't wrapping the global any more
matfournier
@matfournier
I mean yes I can make something new at the top level and manually bump it down to all my calls. It would be nicer if something was inside something like Writer but also MonadError for being able to deal with random jvm exceptions. I am inside an F[Either[Error,A]] and both the error and a failed F get turned into logging messages at the edge of the program right now/.
Gavin Bisesi
@Daenyth
it's hard because you have two failure channels
WriterT[F, Log, ?] as your F would be fine except then F failures don't get logged
You almost need an outer Either[Throwable to catch the F errors
matfournier
@matfournier
I know. The two failure channels is annoying.
Gavin Bisesi
@Daenyth
this is a case where BIO/UIO would be really helpful
but there's not a good cats-generic way for that right now
matfournier
@matfournier
Unfortunately due to the way this is setup + the team, don't think I can use BIO yet
Gavin Bisesi
@Daenyth
You could change Either[Error to Throwable :+: Error :+: A maybe
matfournier
@matfournier
F[Either[Error,A]] atleast roughly breaks down to expected errors in the either, and super-unexpected errors in the F.
Gavin Bisesi
@Daenyth
yeah those "super unexpected" ones have a way of being really common IME
and exceptionally worth logging
matfournier
@matfournier
Yep. Which I am. I just want better logging with a little bit more tracing. Sigh. Thanks for the help!
Rob Norris
@tpolecat
If you have state you need to preserve in case of failure you can stuff it in a Ref.
Arnau Abella
@monadplus
modo compiles, modo2 doesn't. What am I missing ? Maybe it's just type inference
def st: State[S, List[A]]

def modo(f: A => B): IndexedState[S, T, List[A]] =
    Bifunctor[IndexedStateT[Eval, S, ?, ?]].leftMap(st)(traversal.modify(f))

  def modo2(f: A => B): IndexedState[S, T, List[A]] =
    (st: IndexedStateT[Eval, S, S, List[A]]).leftMap(traversal.modify(f))
Arnau Abella
@monadplus
@tpolecat I totally forgot about asking you about Yoneda and Coyoneda. Are you still willing to explain it ?
Arnau Abella
@monadplus
Isn't yoneda similar to a functor ? (forall b. (a -> b) -> f b) ~ f a
Fabio Labella
@SystemFw
Coyoneda is the free functor
and I'd recommend starting from there