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 shapeless._ | |
import scala.language.implicitConversions | |
// object Main extends App { | |
// } | |
object HeterogenousLists extends App { | |
import poly._ | |
object choose extends (Set ~> Option) { |
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
// http://stackoverflow.com/questions/39183041/circe-type-level-json-a-function/39183581#39183581 | |
// https://twitter.com/travisbrown/status/769579633771773954 | |
object Main extends App { | |
import cats.data.Xor | |
import io.circe.{Decoder, DecodingFailure} | |
import shapeless.{Nat, Sized} | |
import shapeless.ops.nat.ToInt | |
import shapeless.syntax.sized._ |
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
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[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
/** | |
* http://stackoverflow.com/questions/39226147/constraint-on-hlist-check-for-single-occurrence-of-a-type/39226608#39226608 | |
*/ | |
import shapeless._, ops.hlist.{ToList} | |
trait T | |
case class TA() extends T | |
case class TB() extends 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
object St0 { | |
type Stack = List[Int] | |
def pop(s0: Stack): (Stack, Int) = | |
s0 match { | |
case x :: xs => (xs, x) | |
case Nil => sys.error("stack is empty") | |
} | |
def push(s0: Stack, a: Int): (Stack, 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
import scalaz._, Scalaz._ | |
object Main extends App { | |
// Scala equivalent of Haskell first and second | |
// http://stackoverflow.com/questions/39457088/scala-equivalent-of-haskell-first-and-second | |
type T2 = Tuple2[Int, Int] | |
val f = (n: Int) => n + 1 | |
val g = (n: Int) => n * 100 |
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 shapeless._ | |
import shapeless.test._ | |
trait Weight[A] { def apply(a: A): Int } | |
object Weight { | |
def apply[A](f: A => Int) = new Weight[A] { def apply(a: A) = f(a) } | |
} | |
case class Foo(i: Int, s: 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
object Main extends App { | |
import io.iteratee.modules.id._ | |
val singleNumE = enumOne(42) | |
val singleNumI = takeI[Int](1) | |
val singleNumResult = singleNumE.into(singleNumI) | |
println(singleNumResult) | |
val incrementNumEE = map[Int, Int](_ + 1) | |
val incrementedNumResult = singleNumE.through(incrementNumEE).into(singleNumI) |
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 CirceMain extends App { | |
import io.circe.Encoder | |
import io.circe.syntax._ | |
case class Person(firstName: String, lastName: String, age: Int) | |
val person = Person("Joe", "Black", 42) | |
{ | |
implicit val personEnc: Encoder[Person] = Encoder.forProduct3( | |
"firstName", "lastName", "age") { |
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
// Using a polymorphic function to extract an object from Options | |
// http://stackoverflow.com/questions/39628022/using-a-polymorphic-function-to-extract-an-object-from-options/39636969#39636969 | |
object Main extends App { | |
import scalaz._, syntax.std.option._ | |
import shapeless._, shapeless.poly.~> | |
val options = 1.some :: "A".some :: 3.5.some :: HNil | |
object uuu extends (Option ~> Id) { |
OlderNewer