## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
• Create your own community
##### Activity
Fabio Labella
@SystemFw
with the right explanations and by reading/writing code, you can understand and use ~all of pure FP without knowing any CT (though most people will pick up some of it almost by accident)
Rob Norris
@tpolecat
Agree with all of that.
Fabio Labella
@SystemFw
but definitely don't fall in the trap of thinking you need to digest a CT book to approach cats or cats-effect
elyphas
@elyphas
:)
thank you both,
Alex Henning Johannessen
@ahjohannessen
Is there some combinator for val a = F[Option[X]]; val b = F[Option[X]] that does a orElse b, now I do (a, b).mapN((a1, b1) => a1.orElse(b1)) - I guess it is something with traverse :D
Rob Norris
@tpolecat
You can do that with OptionT.
(OptionT(a) orElse OptionT(b)).value
You can say <+> instead of orElse, which is cooler. I mean, obviously.
Anton Sviridov
@keynmol
This is offtopic: does anyone here use quiver and/or know who maintains it? I want to publish it for 2.13 but not sure who to contact
Soren
@srnb_gitlab
Ooh! I just did graph stuff here a bit ago

https://gitter.im/typelevel/cats?at=5f64ae7df51808513b4fd4ab

@keynmol it seems https://github.com/getnelson/quiver is the fork you want, no clue who/how to contact tho

Anton Sviridov
@keynmol
ah ok, that's the one I fixed to work with 2.13
Soren
@srnb_gitlab
Honestly I think it'd be useful to create a cats-centric graph library but I'm not at all familiar with the part of graph theory that would say whether or not there's a GraphT monad transformer
And that'd probably be pretty important
Luka Jacobowitz
@LukaJCB
what would a graph monad’s behaviour be?
def flatMap[A, B](fa: Graph[A])(f: A => Graph[B]): Graph[B]
Anton Sviridov
@keynmol
A is probably not going to be the edge or node type, otherwise there's only so much you can do structurally to fit this signature

Quiver is based on a comonad of graph decompositions and it solved my use case without any monadic craziness.

Lack of maintained graph libraries in the ecosystem suggests that either this usecase is super narrow, or people are using a Java library instead

Soren
@srnb_gitlab
The graph decomposition comonad is something I do know about
Anton Sviridov
@keynmol
I linked that blog post just in case, I myself attempted to read it a few times and never got through it :)
Fabio Labella
@SystemFw
ideas here:
• find someone that wants to maintain quiver (which is inspired by fgl btw)
• flesh out the scala port of alga
Paul Snively
@paul-snively
I would bet that Tim Perrett would wish to maintain quiver.
Maybe Rúnar, who wrote it in the first place.
Anton Sviridov
@keynmol
I've created an issue on the nelson fork, hopefully Tim (I've seen Ross Baker there, too) will respond. I have all sorts of cross platform/scala versions publishing and just want to make sure there's actually a release process :)
@arosien
i've wanted to play with alga, looks cool.
Soren
@srnb_gitlab
1. is there a way to automatically optimize non-dependent for-comprehensions into a mapN?
2. is using mapN fine for things that need to be ordered?
3. is using mapN going to give me a speed increase over a for-comprehension when using an effect type?
Ignore how badly written the project is in general; Is it useful to turn the steps not dependent on eachother into mapNs?
Raas Ahsan
@RaasAhsan
1. AFAIK there isn't, for comprehensions always desugar into a series of nested flatMaps. not sure if there are compiler plugins that do otherwise
2. mapN will evaluate effects in the order in which they appear in the tuple
3. likely not, Applicative functions for Monads are usually written in terms of flatMap
Soren
@srnb_gitlab
@RaasAhsan What about IO? Isn't there this thing where mapN on IO/Task parallelize?
Raas Ahsan
@RaasAhsan
it will for Parallel operations like parMapN, but the regular Applicative instances will evaluate sequentially
Soren
@srnb_gitlab
Hmm
Raas Ahsan
@RaasAhsan
mapN will evaluate multiple independent effects sequentially, parMapNwill evaluate multiple independent effects in parallel
Soren
@srnb_gitlab
Can I say "use parMapN if possible, otherwise mapN"?
Raas Ahsan
@RaasAhsan
I think that's reasonable :) but if the effects are very fast to compute or don't involve I/O, the overhead of shifting executors might cause parMapN to be slower
Soren
@srnb_gitlab
hmm
the effects will be very fast to compute so :+1:
I'll just use a for loop
comp
Alex Henning Johannessen
@ahjohannessen
Thanks @tpolecat :)
Enrico Benini
@benkio

A question

https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/data/WriterT.scala#L330

In here liftF requires an Applicative, but it just uses map, why it just don't require a Functor instance?
Cheers

Gavin Bisesi
@Daenyth
Looks likely to be an error.
Ethan
@esuntag
@srnb_gitlab I get joy out of overengineering hackerrank type problems. In this case what it boils down to is you start with an array of Int, and a target value, and you want to find the two values that add up to the target.
def compute[A: Monoid, F[_]: Foldable: Comonad](fa: F[A], target: A): Option[String] =
fa.coflatten.foldMapK(f => {
val a = f.extract
f.foldMapK(b => Option.when((a |+| b) == target)(s"$a$b"))
})
Gavin Bisesi
@Daenyth
oh my
wonder what the asymptotics are on that using list/vector vs zipper
"find the two values" is that pairwise values?
or any two values?
Ethan
@esuntag
There's guaranteed to be a unique solution, so there will be precisely two numbers in the initial array that add up to the target. Still missing the semantics in that disallowing selecting the same one twice, not sure if there's something better than a filter for that
Don't worry, this is going nowhere near production