These are chat archives for typelevel/cats

5th
Dec 2017
Jangoolie
@jangoolie
Dec 05 2017 01:02
I feel like this should be obvious. But what typeclass do I need to do IO.apply like behaviour without the Effect type being known?
Michael Pilquist
@mpilquist
Dec 05 2017 01:03
@jangoolie cats.effect.Sync via the delay method
Jangoolie
@jangoolie
Dec 05 2017 01:10
@mpilquist Ah yup thats it. Should have been obvious considering I'm replacing fs2 Task.delay style code
Michael Pilquist
@mpilquist
Dec 05 2017 01:11
:)
Jangoolie
@jangoolie
Dec 05 2017 01:15
Programming with this F[_] style feels pretty great. It's like Haskell level of abstraction, only with twice the syntax
Marco Battaglia
@marcobattaglia
Dec 05 2017 01:27
Please, one question... I have implemented other method for Arrow composition in class cats.arrow.Arrow. They work fine in concole, but I'm not able to write tests.
I cannot create an implicit Arbitrary[F[A,C]]
Anyone could help me by showing where a similar Arbitrary is created, for example Arbitrary[F[A,B]] ?
out of curiosity, what other methods for Arrow composition have you added?
Marco Battaglia
@marcobattaglia
Dec 05 2017 01:39
@simulacrum.op("&&&", alias = true)
def mergeA, B, C: F[A, (B, C)] = {
andThen(lift((x: A) => (x, x)), split(f, g))
}
and
@simulacrum.op("-<", alias = true)
def combineAndByPassA, B, C(g: F[B, C]): F[A, (B, C)] = {
andThen(lift((x: A) => (x, x)), split(f, andThen(f, g)))
}
examples:
scala> val addEmpty: Int => Int = _ + 0
* scala> val multiplyEmpty: Int => Int= _ * 1d
* scala> val f: Int => (Int, Double) = addEmpty &&& multiplyEmpty
example of -<
  • scala> val twoTimes: Int => Double = _ + 2d
    • scala> val fiveTimes: Double => Double= _ * 5
    • scala> val f: Int => (Double, Double) = twoTimes -< fiveTimes
Fabio Labella
@SystemFw
Dec 05 2017 01:41
```scala
code
```
Marco Battaglia
@marcobattaglia
Dec 05 2017 01:41
thx
we have used in our library, and now we'd like to add in cats
In ArrowTests I have added:
ArbFAC: Arbitrary[F[A, C]],
the compiler says it has no implicit defined in order to generate the Arbitrary
I looked for in cats.laws.discipline something of similar, but without result
Have you any idea ?
Fabio Labella
@SystemFw
Dec 05 2017 01:47
sorry, I need to go now cause it's super late, perhaps someone else can help
Marco Battaglia
@marcobattaglia
Dec 05 2017 01:49
Ok. Good night
zero_coder
@kostonstyle
Dec 05 2017 09:30
How to lift IO[Either[String, KkProducerRecordMetadata]] into EitherT[IO, String, KkProducerRecordMetadata]?
Luka Jacobowitz
@LukaJCB
Dec 05 2017 09:34
How do you turn a KkProducerRecordMetadata into a Vector[KkConsumerRecord]
zero_coder
@kostonstyle
Dec 05 2017 09:35
Sorry, I made a mistake
I updated my post
With EitherT.pure?
Luka Jacobowitz
@LukaJCB
Dec 05 2017 09:37
Nope, just EitherT.apply :D
pure always lifts a pure value into a context
zero_coder
@kostonstyle
Dec 05 2017 09:39
For example EitherT.apply or just like EitherT()?
guillaumecherel
@guillaumecherel
Dec 05 2017 09:42

Hi, I'm trying to use the more efficient IO implementation that was added with the last commit. I've read the doc about snapshots, and guessed that I could use the last commit with the following line in build.sbt:

libraryDependencies += "org.typelevel" %% "cats-effect" % "0.5-964e8d0",

But sbt complains that the dependency is not found. Did I misunderstand, or should I add another resolver?

Luka Jacobowitz
@LukaJCB
Dec 05 2017 09:42
both work
zero_coder
@kostonstyle
Dec 05 2017 09:42
Thanks
Raymond Barlow
@raymanoz
Dec 05 2017 09:48
Hey peeps. Is there an equivalent to this somewhere in cats?
  implicit class PimpAllTheThings[A](val self: A) {
    def left[R]: Either[A, R] = Left(self)
    def right[L]: Either[L, A] = Right(self)
  }
I'm trying to cleanly solve the problem where Right is not Either
Raymond Barlow
@raymanoz
Dec 05 2017 09:51
sweet
Bjørn Madsen
@aeons
Dec 05 2017 10:18
@guillaumecherel it used to be published on maven central
but there’s nothing since 0.5
guillaumecherel
@guillaumecherel
Dec 05 2017 10:30
I see, thanks. I suppose these changes will be included in the next release
Colt Frederickson
@coltfred
Dec 05 2017 15:05
Is there syntax in cats for computing the intersection of 2 structures? I guess it'd be on Foldable, but maybe there's something more general I'm missing.
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:08
Is there a structure such that encodes roundtripping without guarantees like isomorphism. Such that f: A => B, g: B => A, g(f(a)) === a I’m sure its something obvious that I’m missing.
Colt Frederickson
@coltfred
Dec 05 2017 15:09
@ChristopherDavenport That's just function composition because of parametricy, right?
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:10
Yeah. I’ve hit several types where thats my attempt at a guarantee.
Colt Frederickson
@coltfred
Dec 05 2017 15:11
So any Functor should support that, I think?
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:11
Like encoding List[Record] => CSV String => List[Record] should be the same.
Colt Frederickson
@coltfred
Dec 05 2017 15:12
Oh, you're talking about destroying the structure and recreating it.
List ~> Id ~> List
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:12
Yeah. But also for things with A => ZookeeperBytes => A
Colt Frederickson
@coltfred
Dec 05 2017 15:13
F[A] -> G[B] -> F[A] implying that both F[A] are the same .
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:13
Exactly.
I don’t have any fun guarantees on the middle but the traversal shows that my expectations match on both ends.
As I’ve hit the pattern several times, and I know it is almost always what I test with java library interop I’m trying to nail down how I could generalize it. If there is a generalization.
Alexander Konovalov
@alexknvl
Dec 05 2017 15:15
@ChristopherDavenport wdym "no guarantees like isomorphism"?
Do you want only f . g = id to hold, but not necessarily g . f = id?
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:17
String => List[Record] above is not total. There are many strings that would not meet this.
Same with byte structure intermediaries.
Alexander Konovalov
@alexknvl
Dec 05 2017 15:17
so (A => B, B => Option[A])?
Colt Frederickson
@coltfred
Dec 05 2017 15:17
this is roughly A -> Json -> A
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:18
Thats the pattern, my codomain does appear to be off.
Alexander Konovalov
@alexknvl
Dec 05 2017 15:18
That's called Prism.
Colt Frederickson
@coltfred
Dec 05 2017 15:18
Oh ya, that thing. I really should learn more about lenses and prisms.
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:20
Well it was a fundamental. :) If it was a snake I’d be dead.
Fabio Labella
@SystemFw
Dec 05 2017 15:20
yeah, that's pretty much the definition of a Prism
Christopher Davenport
@ChristopherDavenport
Dec 05 2017 15:21
Yeah, the prism laws are exactly what I wanted.
Now I have to figure out how to deal with java libraries and their false codomains and force them into an accurate shape.
But thats a much easier job when you know the right shape.
Luka Jacobowitz
@LukaJCB
Dec 05 2017 15:50
Anyone here have experience creating an http4s API for Spark jobs?
Colt Frederickson
@coltfred
Dec 05 2017 16:02
@LukaJCB That's an interesting question.
https://github.com/spark-jobserver/spark-jobserver is what I've heard of people using to submit jobs if that's what you're doing.
Luka Jacobowitz
@LukaJCB
Dec 05 2017 16:06
Thanks @coltfred! I’m gonna look into that!
Colin Woodbury
@fosskers
Dec 05 2017 17:13
Please let me know if there's anything that needs updating
Fabio Labella
@SystemFw
Dec 05 2017 17:17
@fosskers I don't see why Functional Programming in Scala is more specific to scalaz than cats
Colin Woodbury
@fosskers
Dec 05 2017 17:17
did I claim that somewhere?
Fabio Labella
@SystemFw
Dec 05 2017 17:17
ScalaZ:

Functional Programming in Scala by the ScalaZ authors (for Scala beginners)
Functional Programming for Mortals by Sam Halliday (for FP beginners - assumes an OO Scala background)
Training by the Fantasyland Institute

Cats:

Scala with Cats by Noel Welsh and Dave Gurnell (assumes 1+ years of Scala experience)
Training by Underscore Consultants
Colin Woodbury
@fosskers
Dec 05 2017 17:18
The first book? Yeah I thought it was written by scalaz guys
Fabio Labella
@SystemFw
Dec 05 2017 17:18
it was written by Runar bjarnason and Paul chiusano
way before cats existed
it doesn't use scalaz
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:18
Yeah I was gonna say the same thing
Fabio Labella
@SystemFw
Dec 05 2017 17:18
it builds everything form scratch
and it's the main book for learning FP
Colin Woodbury
@fosskers
Dec 05 2017 17:19
ah, that's news to me. Is it still valuable to list there?
Fabio Labella
@SystemFw
Dec 05 2017 17:19
it's not even really about scala, it's about FP as well
it's the most valuable book to learn FP in Scala
regardless of which library you will apply its principles to
Colin Woodbury
@fosskers
Dec 05 2017 17:19
In that case, I can list that book above either subsection
Fabio Labella
@SystemFw
Dec 05 2017 17:19
:+1:
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:19
:+1:
Fabio Labella
@SystemFw
Dec 05 2017 17:22
It would probably be good to name the authors
it wasn't written by "the scalaz authors", just by Paul and Runar
Colin Woodbury
@fosskers
Dec 05 2017 17:23
reasonable, I'll change that now
Fabio Labella
@SystemFw
Dec 05 2017 17:24
also, doobie and fs2 are in the same situation wrt scalaz
Colin Woodbury
@fosskers
Dec 05 2017 17:25
re: the "gray zone" ?
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:25
Yeah, I was also just about to write that :D
Fabio Labella
@SystemFw
Dec 05 2017 17:25
i.e their old version (current stable) supports both. The milestones have a direct dependency on cats + cats-effect
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:26
Same with Monocle I believe
Colin Woodbury
@fosskers
Dec 05 2017 17:26
I knew about monocle, yeah
Things will resettle when cats 1.0 is out, at which point I'll update the image
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:29
:+1:
Great work otherwise, I can see you put a lot of effort in it!
Colin Woodbury
@fosskers
Dec 05 2017 17:30
thanks, yeah it took a while
the team I work for will be making a call on "one or the other" based on this
but really shims makes it all moot
Luka Jacobowitz
@LukaJCB
Dec 05 2017 17:32
Yeah shims is great!
Though I wonder if it will work with Scalaz 8
Harrison Houghton
@hrhino
Dec 05 2017 17:36
It'll need modified :/
Colin Woodbury
@fosskers
Dec 05 2017 18:14
for sure
Artur Soler
@ArturSoler
Dec 05 2017 18:21
how can I do the short version of Monad[State[MyState, ?]].ifM(myStateInstance)(ifTrue, ifFalse), calling ifM directly on myStateInstance?
when I try that it complains about ifMnot being a method of myStateInstance, because it doesn't have the monad in scope
declaring the monad as implicit doesn't seem to work
Harrison Houghton
@hrhino
Dec 05 2017 18:27
Do you have -Ypartial-unification turned on?
Artur Soler
@ArturSoler
Dec 05 2017 18:28
no, should I add it?
Fabio Labella
@SystemFw
Dec 05 2017 18:30
always have it on
Artur Soler
@ArturSoler
Dec 05 2017 18:34
works now, thanks
didn't know about this setting
Fabio Labella
@SystemFw
Dec 05 2017 18:34
it's on the cats README
but the gist of it is that you should always have it if you want to do scala FP
Stephen Duncan Jr
@jrduncans
Dec 05 2017 18:44
...if only IntelliJ's Scala plugin understood partial unification...I find myself putting type annotations on things to make it happy (using kind-projector to ease the syntax)...
Colin Woodbury
@fosskers
Dec 05 2017 18:55
I'm trying to release my first scala lib. How do the cool kids go about that? I assume there's an sbt plugin floating around. Also, where should I put the published stuff? Scaladex? Is there consensus for where the best place to publish is?
The less config overall, the better
haskell lets me stack upload . so I'm quite spoiled
Luka Jacobowitz
@LukaJCB
Dec 05 2017 19:02
Unfortunately releasing really sucks :D
alex wrote up something recently
Colin Woodbury
@fosskers
Dec 05 2017 19:05
oh no, private keys
Luka Jacobowitz
@LukaJCB
Dec 05 2017 19:06
Yeah, I’m sorry :D
Colin Woodbury
@fosskers
Dec 05 2017 19:09
Thanks, I'll take from that what I can
Justin du Coeur, AKA Mark Waks
@jducoeur
Dec 05 2017 19:11
@fosskers I've got a gorily-detailed description of the process at https://www.querki.net/u/jducoeur/scala-notes/#!Creating-a-Scalajs-Open-Source-Project -- that's nominally aimed at Scala.js libraries, but in practice there is little difference. Note in particular that there are some steps involved in getting your "organization" set up in the first place.
Stephen Duncan Jr
@jrduncans
Dec 05 2017 19:12
The SBT release plugin + SBT Bintray is what I'm planning on using, though I haven't published my open-source project yet: https://github.com/sbt/sbt-release https://github.com/sbt/sbt-bintray (this assumes signing up and setting up on bintray)
Colin Woodbury
@fosskers
Dec 05 2017 19:13
sbt-bintray looks the least painful
Justin du Coeur, AKA Mark Waks
@jducoeur
Dec 05 2017 19:20
Could be, although keep in mind that my huge guide includes, eg, setting up your GitHub account and other stuff that you're probably long past -- don't be too intimidated by the length. Day-to-day running on Sonatype is pretty straightforward, but setting it up is a mild hassle.
Colin Woodbury
@fosskers
Dec 05 2017 19:26
thanks