Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Luis Miguel Mejía Suárez
@BalmungSan
Because it seems you just want: Right(either.toOption)
sken
@sken77
yes
i just wanted as a dot function so it doesnt cut the flow
@BalmungSan
Luis Miguel Mejía Suárez
@BalmungSan
either.map(_.some) ?
sken
@sken77
huh let me try
well that wouldnt work, because i want the error to turn into None
that returns Either[E, Option[A]]
Luis Miguel Mejía Suárez
@BalmungSan
Ah right.
either.toOption.asRight[E]
sken
@sken77
thanks
that does it
Jorge Adriano Branco Aires
@jorgeadriano
Is there nothing in cats to go from a List[E] of errors to a ValidatedNel[E, Unit]? E.g.,
def fromListErrors[E](xs: List[E]): ValidatedNel[E, Unit] =  
   xs.toNel.fold((().valid))(_.invalid)
Adam Rosien
@arosien
there's probably lots of ways. how about xs.foldMap(_.invalidNel)?
oh, that's doesn't nel check. something like that
Jorge Adriano Branco Aires
@jorgeadriano
@arosien nah, that works well, much neater than my implementation above.
TH Lim
@sshark
is there a new version for log4cats for Scala 3? I cannot find it in https://repo1.maven.org/maven2/io/chrisdavenport/
Luis Miguel Mejía Suárez
@BalmungSan
@sshark log4cats was moved to the typelevel organization: https://mvnrepository.com/artifact/org.typelevel/log4cats-core
otto-dev
@otto-dev
Is there a symbolic operator alias for .fmap? Just like >>= is an alias for flatMap?
1 reply
joules-o
@joules-o
I have val a: EitherT[F, E, Option[A], and want to call a secondary function def b: EitherT[F, E, A] iff a is Left OR a is Right(None). What's the best way to do this?
Adam Rosien
@arosien
it depends what output type you want, but you can start with EitherT#fold
joules-o
@joules-o
I want the output type to be EitherT[F, E, A], and ideally, I'd like to only invoke fn b once
Adam Rosien
@arosien
the Left handling is easy, that's a.orElse(b.map(Some.apply))
probably EitherT(a.fold(somethingThatProducesEither))
Adam Rosien
@arosien
EitherT(a.value.flatMap {
  case Left(_) => b.value
  case Right(None) => b.value
  case Right(Some(a)) => Monad[F].pure(Right(Some(a)))
})
is one way
a.biflatMap(
      _ => b,
      {
        case None => b
        case Some(a) => EitherT.rightT(a)
      }
    )
returns EitherT[F, E, A]
joules-o
@joules-o
Is there a way to only invoke b once, besides something like EitherT(a.toOption.getOrElseF(b.value))?
Adam Rosien
@arosien
b is only invoked once in each case afaict
Leif Warner
@LeifW
Is there something for for a boolean-guarded monadic action, e.g. https://hackage.haskell.org/package/base-4.15.0.0/docs/Control-Monad.html#v:when ?
Oh, I see there's a whenA method on Monad.
Carlos Verdes
@carlos-verdes
hi all, I'm using spec2 to do some testing and using resultValue for effects, some of my tests expects a Throwable as part of a MonadThrow (F.raiseError) but I can't find the way to write a matcher for that
Has anyone solved that issue?
Maatary
@Maatary
Hi there, looking for a functional parser combinator library that can work with generic input i.e. other than text/string ? any recommendation
martijn.hoekstra.zivver
@martijn.hoekstra.zivver:matrix.org
[m]
there is no implict Monoid[F[A]] for F[]: Monad and A: Monoid if I just import cats.implicits.
is it elsewhere? Or is there another reason it's not available by default
(or at all)
David Geirola
@geirolz
Hi guys, there is syntax to lift IO[Option[T]] into OptionT[IO, T] ? I'd like to avoid using OptionT apply method and have some method to chain with dot notation
Luis Miguel Mejía Suárez
@BalmungSan
@geirolz does value.lift[OptionT[IO, *]] work?
1 reply
So you need to do something like this:
def foo[F[_], A](f1: F[A], f2: F[A])(implicit ev1: Applicative[F], ev2: Monoid[A]): F[A] = {
  implicit val monoidFA: Monoid[F[A]] = ev1.monoid

  f1 |+| f2
}
martijn.hoekstra.zivver
@martijn.hoekstra.zivver:matrix.org
[m]
Thanks Luis. I wonder why it's not implicit
maybe it leads to ambiguous impicits
Luis Miguel Mejía Suárez
@BalmungSan
@martijn.hoekstra.zivver:matrix.org Probably, no idea.
Valdemar Grange
@ValdemarGr

Hello.

How do people deal with dependency injection in production applications? We have been running with Reader and Kleisli for a while, but the same thing keeps coming up; narrowing large dependency types. An anonymous product type (Tuple) would, at first glance, seem quite relevant to solve this, say Kleisli[F, (Client[F], BlobStore[F], Transactor[F]) Unit], but this method of encoding dependencies quickly becomes unwieldy. For instance, (Configuration, BlobStore[F], Logger[F], transactor.Transactor[F], Client[F], EntryPoint[F]) which is a type from a relatively simple application becomes quite verbose to handle. The problem arises from narrowing the dependency list. Without going into specifics, at the toplevel the following narrowing occurs:

.run((config, bs, lg, xa, c, ep)),
.run((config, lg, c, ep)),
.run((config, lg, xa, c, ep, bs))

The promises of Reader and Kleisli to remove much noise given some constraints on F seem to disappear once types become lage enough. local obviously can alleviate the pain, if for instance, everyone required one dependency, but alas this is not the case.
We have considered an alternative that uses ad-hoc polymorphism and subtyping (a rough sketch here https://scastie.scala-lang.org/H29nvk2ESVqaIKXAs2ayKw).

Thank you :)

Luis Miguel Mejía Suárez
@BalmungSan
I really can't understand why people won't just pass dependencies on constructors / methods.
Valdemar Grange
@ValdemarGr

When classes become large enough, there may be a set of methods which require but a subset of the dependencies thus become difficult to test. Introducing dependencies on the functions instead alleviates this.

Moving dependencies to methods is a constant reduction in noise.

Guice, albeit runtime and all that jazz, removes much of the noise of dependency injection. Obtaining an equivalent noise reduction, but on the function instead, without any magic involved is what I am looking for :)

Luis Miguel Mejía Suárez
@BalmungSan
I mean, I don't want to sound rude I hope you find the answer you are looking for.
I just wanted to bring the perspective that for me just passing things explicitly be it a constructor level or method level is simpler.
Anyways, @ValdemarGr you may want to ask your question again in the discord server, many folks migrated there.
Valdemar Grange
@ValdemarGr
No worries @BalmungSan, thank you :)