Operation | Input | Result | Notes |
---|---|---|---|
map | F[A] , A => B |
F[B] |
Functor |
apply | F[A] , F[A => B] |
F[B] |
Applicative |
(fa, fb, ...).mapN | (F[A], F[B], ...) , (A, B, ...) => C |
F[C] |
Applicative |
(fa, fb, ...).tupled | (F[A], F[B], ...) |
F[(A, B, ...)] |
Applicative |
flatMap | F[A] , A => F[B] |
F[B] |
Monad |
traverse | F[A] , A => G[B] |
G[F[A]] |
Traversable; fa.traverse(f) == fa.map(f).sequence ; "foreach with effects" |
sequence | F[G[A]] |
G[F[A]] |
Same as fga.traverse(identity) |
attempt | F[A] |
F[Either[E, A]] |
Given ApplicativeError[F, E] |
. | . | . | . |
Stream.emit | A | Stream[Pure, A] | |
Stream.emits | Iterable[A] | Stream[Pure, A] | |
stream.covary[F] | Stream[Pure, A] | Stream[F, A] | Often useful after emit or emits . ; F is anything with cats-effect Effect[F] available. Usually cats.effect.IO |
Stream.eval | F[A] | Stream[F, A] | F: Effect |
stream.evalMap | Stream[F, A] , A => F[B] | Stream[F, B] | Run an effect for each element in the stream, returning each result |
stream.evalTap | Stream[F, A], A => F[Unit] | Stream[F, A] | Run an effect for each element in the stream, ignoring the result |
stream.compile.drain | Stream[F, A] | F[Unit] | Translate the stream description to a description of effects |
stream.compile.toVector | Stream[F, A] | F[Vector[A]] | Translate the stream description to a description of effects returning a vector |
Last active
June 25, 2024 13:04
-
-
Save Daenyth/75d3b4edd415fc2de12b0cf5d26e7a9d to your computer and use it in GitHub Desktop.
Cheat sheet for common cats monad and fs2 operation shapes
Another cats typeclass function signature listing: https://arosien.github.io/cats-cheatsheets/typeclasses.pdf
A graphic diagram of typeclass relationships: https://github.com/tpolecat/cats-infographic
Shapless symbols can maybe be found here:
https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.0.0
Slick symbols:
http://slick.lightbend.com/doc/3.0.0/genindex.html#Symbols
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also helpful: https://typelevel.org/cats/faq.html#symbol