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.arrow.FunctionK | |
import cats.data.{ReaderWriterState} | |
import cats.free.Free | |
/* utilities for using free as eff */ | |
extension [S[_], A] (free: Free[S, A]) { | |
def widenEffect[R[_]](using subtype: S[A] <:< R[A]): Free[R, A] = { | |
free.asInstanceOf[Free[R, 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
object HTMLInterpolation { | |
// definition of tagged type | |
type Tagged[U] = { type Tag = U } | |
type @@[T, U] = T with Tagged[U] | |
trait Sanitized | |
// use tagged type to express sanitized string | |
type SanitizedString = String @@ Sanitized |
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 StringContext (ss: String*) { | |
def s (n: Int): String = ss(n) | |
} | |
object StringContextTest { | |
def main (args: Array[String]): Unit = { | |
println(s"foo${1}bar") // print bar (not foo1bar) | |
} | |
} |
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 combinator._ | |
object PrinterExamples extends BytePrinters { | |
def u2_s4_data: BytePrinter[(Int, Int)] = { | |
case (a, b) => u2(a) >> s4(b) | |
} | |
def length_bytes: BytePrinter[Array[Byte]] = bs => for { | |
_ <- u2(bs.length) | |
_ <- bytes(bs) | |
} yield () |
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._ | |
import scalaz._ | |
import scalaz.std.list._ | |
import scalaz.syntax.traverse._ | |
// Tries.scala (https://gist.github.com/phenan/63833c2cc715c96c02a4c33e17d9e2ac) | |
import tries._ | |
/** |
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._ | |
import scalaz.std.list._ | |
import scalaz.syntax.traverse._ | |
// Tries.scala (https://gist.github.com/phenan/63833c2cc715c96c02a4c33e17d9e2ac) | |
import tries._ | |
/** | |
* Created by phenan on 2017/10/18. |
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 org.scalatest._ | |
import scalaz._ | |
import tries._ | |
/** | |
* Created by phenan on 2017/10/19. | |
*/ | |
class TriesTest extends FunSpec with DiagrammedAssertions { |
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 scalaz._ | |
/** | |
* Tries[T] is a type alias of Throwable \/ T. | |
* It can be used in the same manner as scala.util.Try but it is an instance of monad unlike Try. | |
* | |
* Created by phenan on 2017/10/18. | |
*/ | |
package object tries { | |
type Tries[+T] = Throwable \/ T |
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.language.higherKinds | |
import scalaz._ | |
import scalaz.std.option._ | |
import scalaz.syntax.monadPlus._ | |
trait Parsers [Elem, C[+_], Repr[+_, _, _[_]]] { | |
def cond (f: Elem => Boolean): Repr[Elem, Elem, C] | |
def elem (e: Elem): Repr[Elem, Elem, C] = cond(_ == e) | |
def success [T] (r: T): Repr[T, Elem, C] | |
def failure (msg: String): Repr[Nothing, Elem, C] |
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._ | |
import scala.util.Try | |
class ByteReader private (in: DataInputStream) { | |
def u1: Int = read(1, in.readUnsignedByte()) | |
def u2: Int = read(2, in.readUnsignedShort()) | |
def s1: Int = read(1, in.readByte().toInt) | |
def s2: Int = read(2, in.readShort().toInt) |
NewerOlder