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 Test { | |
type Paged[A] = Single[(A, Option[Single[_]])] | |
val s: Paged[Int]= Single((1, Some(Single((2, None))))) | |
def recurse[A](paged: Paged[A]): Observable[A] = paged | |
.toObservable | |
.flatMap { | |
case (i, None) => Observable(i) | |
case (i, Some(page: Paged[A])) => Observable.pure(i) ++ recurse(page) | |
} | |
def main(args: Array[String]): Unit = { |
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
//Say we have a function which returns a custom error | |
def process(line: String, max: Int): Try[Int] = { | |
if(line.length < max) Success(line.toInt) else Failure(new IllegalArgumentException(s"$line is longer than $max")) | |
} | |
//and we want to process a stream of them, but stop when there is an error | |
def pipe[F[_]](max: Int)(implicit F: Async[F]): Pipe[F, String, Int] = { | |
stream => stream.flatMap { line => | |
process(line, max) match { | |
case Success(value) => Stream.pure(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
//Consider the following DSL for a representation of something which can have a get and a put | |
case class Get(key: String) extends DSL[String] | |
case class Put(key: String, value: String) extends DSL[String] | |
//When using it like, | |
for { | |
v <- lift(Get(key)) | |
_ <- lift(Put(key, v)) |
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 Foo[A] { | |
type Out | |
def apply(): Out | |
} | |
object Foo { | |
type Aux[A, B] = Foo[A] { type Out = B } | |
implicit val bfoo: Aux[Bar, Int] = new Foo[Bar] { | |
type Out = 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
package iliad | |
import shapeless._ | |
import scala.annotation.implicitNotFound | |
import scala.reflect.ClassTag | |
@implicitNotFound(msg = "Cannot find PolyTC typeclass for ${TC} in list ${L}.") | |
trait PolyTC[L <: HList, F[_], TC[_[_]], A, B] { | |
def apply(a: F[A])(f: (F[A], TC[F]) => B): 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
trait Functor[F[_]] { | |
def map[B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Monoid[F[_]] { | |
//boils down to F.pure(identity) | |
def identity[A]: F[A => A] | |
//This combine is 'higher' order http://stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-issue' | |
def combine[F[_] : Functor, A](ffa: F[F[A]]): 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
package iliad | |
package platform | |
package gl | |
package es3 | |
import java.nio._ | |
import Constant._ | |
import cats._ | |
import cats.data._, cats.std.all._ |
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
;; global variables | |
(setq | |
inhibit-startup-screen t | |
create-lockfiles nil | |
make-backup-files nil | |
column-number-mode t | |
scroll-error-top-bottom t | |
show-paren-delay 0.5 | |
use-package-always-ensure t | |
sentence-end-double-space nil) |
NewerOlder