Skip to content

Instantly share code, notes, and snippets.

View andyscott's full-sized avatar
🌲

Andy Scott andyscott

🌲
View GitHub Profile
/* -
* Mezzo [core]
*/
package mezzo
import scala.Predef.<:<
import scala.reflect.ClassTag
import shapeless._
@andyscott
andyscott / generic-unzip.scala
Last active May 10, 2018 21:50
Generic unzip Lists[TupleN] with Shapeless
import shapeless._
object emptyList extends Poly0 {
implicit def default[T] = at[List[T]](List.empty)
}
object appendList extends Poly2 {
implicit def default[T] = at[T, List[T]](_ :: _)
}
import com.typesafe.config.Config
import classy.core.Decoder
import classy.generic.derive._
import classy.config._
case class Bar(value: String)
case class Foo(
a: String,
b: Option[Int],
c: List[String],
import cats._
import cats.syntax.all._
object FooAlgebra {
sealed trait Op[A]
case object Foo extends Op[String]
case class FooOps[F[_]](lift: Op ~> F = interpreter) {
def foo(): F[String] = lift(Foo)
}
object StateTExtras {
// this is your brain, on drugs
implicit class StateTTupler[F[_]: Monad, S, A](state: StateT[F, S, A]) {
def tupled2_1[R2]: StateT[F, (S, R2), A] =
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s))
def tupled2_2[R1]: StateT[F, (R1, S), A] =
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s))
implicit class StateTProjections[F[_]: Monad, S, A](state: StateT[F, S, A]) {
def project2_1[R2]: StateT[F, (S, R2), A] =
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s))
def project2_2[R1]: StateT[F, (R1, S), A] =
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s))
def project3_1[R2, R3]: StateT[F, (S, R2, R3), A] =
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s))
import cats._
import monix.eval.Task
import monix.execution.Scheduler
import scala.concurrent.Await
import scala.concurrent.duration._
object FizzBuzzer {
def main(args: Array[String]): Unit = {
import cats._
import cats.data.OptionT
import cats.free._
import cats.syntax.option._
import shapeless.{ Id ⇒ _, _ }
import shapeless.labelled.{ field, FieldType }
//import shapeless.ops.record._
import shapeless.syntax.RecordOps

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
// toying with some abstractions with akka
trait Pipeable[F[_]] {
def pipe(value: F[_], target: ActorRef)(implicit sender: ActorRef = ActorRef.noSender): Unit
}
object Pipeable extends PipeableImplicits {
def apply[F[_]](implicit ev: Pipeable[F]): Pipeable[F] = ev
}
sealed trait PipeableImplicits {