This file contains hidden or 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
| // Passing an extra argument into a polymorphic function? | |
| // http://stackoverflow.com/questions/39628068/passing-an-extra-argument-into-a-polymorphic-function/39637253#39637253 | |
| object Main extends App { | |
| import shapeless._, shapeless.poly.~> | |
| val lists = List(1,2) :: List("A", "B") :: List(1.1, 2.2) :: HNil | |
| { | |
| class sss(i: Int) extends (List ~> Set) { |
This file contains hidden or 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
| // Pick out the Nth element of a HList of Lists and return that value as a HList of values | |
| // http://stackoverflow.com/questions/39584034/pick-out-the-nth-element-of-a-hlist-of-lists-and-return-that-value-as-a-hlist-of/39594978#39594978 | |
| object Main extends App { | |
| import shapeless._ | |
| val a = List(1,2,3) :: List("a", "b", "c") :: List(true, false, true) :: HNil | |
| trait RowSelect[L <: HList] extends DepFn2[L, Int] { | |
| type Row <: HList |
This file contains hidden or 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 { | |
| val f = (_: Int) * 2 | |
| val g = (_: Int) + 2 | |
| val h = (_: Int) * 3 | |
| { | |
| import scalaz.{IList, Endo} | |
| import scalaz.syntax.foldable._ | |
| val hh = IList( |
This file contains hidden or 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
| // https://www.scala-exercises.org/doobie | |
| import doobie.imports._ | |
| import scalaz._, Scalaz._ | |
| import scalaz.concurrent.Task | |
| import shapeless._ | |
| object Main extends App { | |
| val program = 42.point[ConnectionIO] | |
| val xa = DriverManagerTransactor[Task]( |
This file contains hidden or 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
| // https://github.com/adelbertc/faq/blob/master/src/main/tut/typeclasses.compiled.md | |
| object Main extends App { | |
| def sumInts(list: List[Int]): Int = list.foldRight(0)(_ + _) | |
| def concatStrings(list: List[String]): String = list.foldRight("")(_ ++ _) | |
| def unionSets[A](list: List[Set[A]]): Set[A] = list.foldRight(Set.empty[A])(_ union _) | |
| trait Monoid[A] { |
This file contains hidden or 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 { | |
| type II = Int \/ Int | |
| def l(idx: Int): II = { println(s"l($idx)"); 0.left } | |
| def r(idx: Int): II = { println(s"r($idx)"); 1.right } | |
| var idx = -1 | |
| val xs: Stream[II] = Stream(0, 0, 1, 0, 1) map { x => idx += 1; if (x == 0) l(idx) else r(idx) } | |
| def leftIsLeft() |
This file contains hidden or 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 { | |
| implicit class verbose[A] (a: A) { | |
| def v[B](log: B): A = { | |
| println(log) | |
| a | |
| } | |
| } |
This file contains hidden or 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/39794943/map-hlist-with-default/39795173#39795173 | |
| import shapeless._ | |
| case class Foo() | |
| trait Wrapper | |
| case class S(s: String) extends Wrapper | |
| case class I(i: Int) extends Wrapper |
This file contains hidden or 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 scalaz._, Scalaz._ | |
| object Main extends App { | |
| case class Foo(x: String, y: Int, z: Boolean) | |
| case class Bar(x: String, y: Int, z: Boolean) | |
| val fooGen = Generic[Foo] | |
| val barGen = Generic[Bar] |
This file contains hidden or 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.syntax.show._ | |
| import atto._, Atto._ | |
| object Main extends App { | |
| case class Prof[A]( | |
| name: String, | |
| age: Int, | |
| students: List[A] | |
| ) |