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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import slick.lifted.Rep | |
import slick.ast.Ordering.Direction | |
import slick.ast.Ordering | |
import slick.lifted.Query | |
import slick.lifted.ColumnOrdered | |
import slick.lifted.Ordered | |
import scala.util.control.NoStackTrace | |
case class PageRequest(offset: Int, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.{Contravariant, Functor, Semigroupal} | |
import slick.jdbc.{ | |
GetResult, | |
PositionedParameters, | |
PositionedResult, | |
SetParameter | |
} | |
trait RawSqlInstances { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.Async | |
import doobie.util.transactor.Transactor | |
import scala.concurrent.ExecutionContext | |
trait DoobieSlickCompat { | |
/** Create a Doobie Transactor backed by the same Jdbc DataSource as the live slick Database */ | |
def transactorFromSlick[F[_]: Async]( | |
slickDb: slick.jdbc.JdbcBackend#Database, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a | |
ajaja | |
ajowan | |
aka | |
akala | |
akali | |
akan | |
akasa | |
ake | |
akeki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2019-2021 github.com/daenyth | |
// Under the MIT license | |
/* | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE |
"Monad" is a word that describes a set of behaviors
In scala, we use the Monad[Foo]
typeclass from cats to define instances of this behavior.
The essence of its behavior is the ability to describe a series of computations, where one computation depends on the result of the computation that came before it.
For example, Monad[Option]
shows that the Option[A]
data type can be used to describe computations of A
which may result in no value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Monad | |
import cats.effect.concurrent.{Ref, Semaphore} | |
import cats.effect.{Concurrent, Resource} | |
import cats.implicits._ | |
import fs2.{Pipe, Stream} | |
import fs2.concurrent.{NoneTerminatedQueue, Queue} | |
/** Represents the ability to enqueue keyed items into a stream of queues that emits homogenous keyed streams. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.URL; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
/** | |
* Given a url to a web page, extract a suitable image from that page. This will | |
* attempt to follow a method similar to Google+, as described <a href= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.Sync | |
import io.chrisdavenport.log4cats.Logger | |
import cats._ | |
import cats.implicits._ | |
import scala.concurrent.duration._ | |
class RetryExample[F[_]](implicit F: Sync[F], log: Logger[F]) { | |
case class ApiError(msg: String) extends Exception(msg) | |
private def getTempFromInternet: EitherT[F, ApiError, Float] = ??? |