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 scala.annotation.tailrec | |
object FoldFun { | |
// Option | |
// List | |
// Vector | |
trait Foldable[F[_]]{ self => | |
import cats.Monoid | |
import cats.Eval |
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.Applicative | |
import cats.implicits._ | |
import scala.annotation.tailrec | |
object TraverseDiscovery { | |
// trait Traverse[F[_]]{ | |
// def traverse[G[_]: Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]] | |
// } | |
def myTraverse[G[_]: Applicative, A, B](fa: List[A])(f: A => G[B]): G[List[B]] = { |
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._ | |
import cats.data._ | |
import cats.implicits._ | |
import cats.effect._ | |
import scala.util.Try | |
object LoggingInPureFunctions { | |
// Writer[Vector[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
import cats._ | |
import cats.data._ | |
import cats.implicits._ | |
object ValidateMyExistence { | |
// Say you are writing a password change application. | |
// You are given a username, an old password, and a new password | |
case class PasswordChangeRequest(username: String, oldPassword: String, newPassword: String) | |
// We have a set of rules we would like to enforce on this data, | |
// and would like to ensure that all of them are correct, |
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
// example | |
private[service] def sendNelAlertsByPost(alerts: NonEmptyList[Alert], uri: Uri, client: Client): Task[List[Alert]] = { | |
val reqt: Task[Request] = POST(uri, alerts.toList.asJson) | |
val log: Task[Unit] = reqt.flatMap(req => req.bodyAsText.runLog.map(vs => | |
req.toString + " body:" + vs.fold[String]("")(_ + _)) | |
) | |
.flatMap(s => Task(println("**REQUEST**: " + s))) | |
val expect = client.expect(reqt)(jsonOf[List[Alert]]) | |
log *> expect | |
} |
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
trait Show[A] { | |
def show(a: A): String | |
} | |
object Show { | |
def apply[A](f: A => String): Show[A] = new Show[A] { | |
override def show(a: A): String = f(a) |
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
"(.*)" should { | |
"(.*)" in ({.*\n.*\n.*\n.*\n.*\n.*\n }) | |
} | |
find | |
-------------------------------------------------------------- | |
replace | |
$1 should | |
$2 $eXXXX |
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
case class DoSomething() | |
class ComputationActor extends Actor with Listeners { | |
def receive = listenerManagement orElse { | |
case DoSomething() = gossip(doSomething()) | |
} | |
def doSomething(): Compuation = ??? | |
} |
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
/** | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF licenses this file to You under the Apache License, Version 2.0 | |
* (the "License"); you may not use this file except in compliance with | |
* the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* |
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
@namespace("com.example") | |
/** | |
This is a comment for the whole protocol | |
*/ | |
protocol Example { | |
/** | |
The comment applies to the `NoSpaces` record, but is not indented to the |