Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Fabio Labella
@SystemFw
I worry more about gitter getting shutdown at brief notice
Gavin Bisesi
@Daenyth
I learn and internalize the things I teach better, in conversation, than trying to lecture
At least gitter is indexed on google
Some option to grab archives from there
Fabio Labella
@SystemFw
oh yeah still miles better than the proposed alternatives (which is why I opposed migrating to Discord or Slack)
Nathaniel Fischer
@kag0
https://typelevel.org/cats/datatypes/either.html#solution-2-adts-all-the-way-down talks about error ADTs, what's SOP for common errors that you want to share across modules?
Nick Telford
@nicktelford
Is there anything stopping cats from defining typeclass instances for SeqMap? It's useful for preserving the ordering of the mapping.
Jasper Moeys
@Jasper-M
Is there some well known name for this method foo?
def foo[A, B, C](f: A => B)(g: (A, B) => C): A => C =
  a => g(a, f(a))
Fabio Labella
@SystemFw
@Jasper-M that seems equivalent of Applicative.ap for F = A =>, with uncurrying and tuple == parameter lists
but it's not worth writing it differently than what you have I don't think
you can notice by changing (A, B) => C into A => B => C
then factorising the whole signature into (A => B) => (A => (B => C)) => (A => C)
then abstracting A => into F[_]
F[B] => F[B => C] => F[C]
and then alfa-rename and switch order into
F[A => B] => F[A] => F[B], which is the key signature of the Apply typeclass
Fabio Labella
@SystemFw
for F[E] = E => *
(renamed some type variables for clarity)
Jasper Moeys
@Jasper-M
Thanks! I felt like there had to be some cats concept for this
Fabio Labella
@SystemFw
one of the key soft skills is an eye for spotting F[_] patterns
in particular the starting point could have have swiping f and g and noticing basically (A => B) => (A => C)
that should trigger your functorial warning, since functor, applicative and monad can all be seen to transform things into F[B] => F[C]
although it's easier to rename things to F[A] => F[B] for consistency with the way things are usually written down
map: (A => B) => (F[A] => F[B])
ap: F[A => B] => (F[A] => F[B])
flatMap: (A => F[B]) => (F[A] => F[B])
Jasper Moeys
@Jasper-M

one of the key soft skills is an eye for spotting F[_] patterns

I'll tell that to my manager when he starts about communication and presenting

Fabio Labella
@SystemFw
which also helps with understanding that the real difference between power in the three typeclasses reflects the difference in power between A => B (uneffectful), F[A =>B](effectful but no context sensitivity) and A => F[B] (the effect can depend on the output of the previous computation, since A => F

I'll tell that to my manager when he starts about communication and presenting

ahahhaha :+1:

Adam Rosien
@arosien
traverse: (A => G[B]) => (F[A] => G[F[B]])
(kind of like flatMap wooo)

https://typelevel.org/cats/datatypes/either.html#solution-2-adts-all-the-way-down talks about error ADTs, what's SOP for common errors that you want to share across modules?

i think usually you have a separate ADT that is shared across modules. if you can have direct dependencies, then the upper ADT can refer directly to the module error types. otherwise you can cast or translate the module errors into something like Throwable which the upper ADT wraps

Nathaniel Fischer
@kag0
@arosien thanks, that makes sense. I was thinking of doing the opposite - having service specific errors extend common errors. but that just seemed messy.
Adam Rosien
@arosien
agreed!
you probably don't need it, and it's more complicated, but you could have a typeclass that translates "lower" level errors into a "higher" level error, but that means the higher level error loses information (which may be ok)
Nathaniel Fischer
@kag0
that could be interesting
I was already thinking of having a chain of causes similar to exceptions, so details could be retained that way
Soren
@srnb_gitlab
image.png
This just means that for a foo: Foo => Bar I can get a mFoo: M[Foo] => M[Bar], right?
(H is a monad)
Soren
@srnb_gitlab
Also, does "[a] monad on the category of something" mean that something is a Monad? (I don't know a lot of the notation and terminology for all of this)
Ryan Peters
@sloshy
@srnb_gitlab yes. Consider the age-old "a Monad is just a monoid in the category of endofunctors" for another example
Soren
@srnb_gitlab
@sloshy Cool. I'm implementing the H monad from https://arxiv.org/pdf/1804.09408.pdf now
And I think I get most of it
Unfortunately its easier to implement map and flatten than flatMap
Soren
@srnb_gitlab
@sloshy Am I misreading or does the H monad only define the pure operation over directed hypergraphs?
Soren
@srnb_gitlab
Nevermind, I forgot that I can represent any value as a unary sourced hypergraph
What do I do when I don't think its possible to implement tailRecM?
PandaSeal20
@PandaSeal20
Hi all, I am an intermediate scala developer I suppose you might say. I am introducing cats to my work codebases. One problem I seem to have run into is that there is one data type that I find really useful and use for almost everything - EitherT. I want to branch out and use other datatypes, I just find I can code so much faster using this and it does exactly what I need in a lot of cases. I've also used resource, validated and a couple of other ones which worked well. Any advice on how to branch out in Cats, what are some other useful parts of the cats library I should be using? At work I have to do a lot of validation, so having a nice long for comprehension that will shortcircuit on the left works nicely.
Louis Bettens
@lourkeur

Is this a known infringement of Order laws by FloatOrder and DoubleOrder?

cats.kernel.laws.discipline.OrderTests[Float].laws.partialCompare(Float.NaN, Float.NaN) 
  // => IsEq(false, true)
cats.kernel.laws.discipline.OrderTests[Float].laws.partialCompare(-0f,0f) 
  // => IsEq(false, true)

This comes down to java.lang.Float being inconsistent with builtin float by design

Yilin Wei
@yilinwei
@srnb_gitlab tailRecM practically speaking is a stack safe flatMap (the Either represents whether to terminate or keep recursing). You may not be able to implement a stack safe one easily, but you should at least be able to match the signature. Take a look at the existing data types tailRecM to get some ideas of how to write them.
Louis Bettens
@lourkeur
@lourkeur #855