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
CREATE TABLE link ( | |
ID serial PRIMARY KEY, | |
name VARCHAR (255) NOT NULL, | |
other VARCHAR (255) NOT NULL, | |
score INT NOT NULL | |
); | |
INSERT INTO link (name, other, score) | |
VALUES | |
('Foo', 'ABC' , 13), |
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.{ExitCode, IO, IOApp, Resource} | |
import scala.util.Random | |
object Demo extends IOApp { | |
var i = 0 | |
def foo: IO[Int] = IO{ | |
i = i + 1 | |
i | |
}.flatTap( | |
j => IO{ |
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.util.concurrent.Future | |
import cats.Applicative | |
import cats.effect.{Concurrent, Sync, Timer} | |
import cats.effect.concurrent.Deferred | |
import fs2.Stream | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
import scala.concurrent.duration.FiniteDuration |
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
object Demo { | |
def getMedian(ints:List[Int]): Int = ints.sorted.apply(ints.length / 2) | |
//sorry no shapless here. all these lists have the same length. in two dimensions they will have length two. | |
case class Point(coordinates: List[Int]) | |
object Point{ | |
def in2D(x: Int, y: Int): Point = Point(List(x,y)) | |
def estimateNearestPoint(points: List[Point], point: Point): Point = { | |
val indexOfPointWithSmallestDistance: Int = points |
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
package com.itv.sif.db | |
import cats.effect.IOApp | |
import java.util.concurrent.Executors | |
import fs2.Stream | |
import cats.syntax.functor._ | |
import scala.concurrent.ExecutionContext | |
import cats.effect._ |
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
package com.itv.sif.db | |
import cats.{Order, Show} | |
import cats.data.{Ior, NonEmptyList, NonEmptySet, Validated} | |
import cats.kernel.Semigroup | |
import cats.syntax.apply._ | |
import cats.syntax.option._ | |
import cats.syntax.order._ | |
import cats.syntax.show._ |
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.data.{Ior, NonEmptyList, NonEmptySet} | |
import io.circe.Json | |
object demo2 { | |
type TimeStamp = Long | |
type Identifier = Long //unique identifier, ie: ccid + streaming-platform perhaps? | |
type Reason = String | |
//Having two tables, storing only validated data in the Success table, and storing unavailability reasons in the other table. |
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
package com.itv.sif.db | |
import cats.Show | |
import cats.data.{NonEmptyList, NonEmptySet, Validated} | |
import cats.syntax.apply._ | |
import cats.syntax.either._ | |
import cats.syntax.validated._ | |
import cats.syntax.show._ | |
import cats.instances.all._ | |
import cats.kernel.Semigroup |
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.data.{NonEmptyChain, NonEmptyList, Validated, ValidatedNec} | |
import cats.syntax.apply._ | |
import cats.syntax.option._ | |
import cats.syntax.either._ | |
import cats.instances.all._ | |
//just a demonstration of aggregating partial updates in a flattened model | |
object partialUpdateBasicDemo extends App { | |
type A = String |
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
(defn is_divisible [n m] (= (mod n m) 0)) | |
(defn is_prime[n] | |
(every? | |
#(not (is_divisible n %)) | |
(range 2 (- n 1)))) | |
(take-last 3 (filter is_prime (range 1 20))) |