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
case class Foo(a: Int, b: String, c: Bar) | |
case class Bar(x: Int, y: Baz) | |
case class Baz(z: String) | |
// Each case class can be generalized in to a product, where that product is just the parts of the case class | |
// Foo === Int :: String :: Bar :: HNil | |
// Bar === Int :: Baz :: HNil | |
// Baz === String :: HNil |
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
case class IO[A](unsafePerformIO: () => A) { | |
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO())) | |
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO()) | |
def tryIO(ta: Throwable => A): IO[A] = | |
val attempt = IO(() => IO.tryIO(unsafePerformIO()) // lift IO[A] to IO[Either[Throwable,A]] | |
attempt.unsafePerformIO() match { | |
case Left(t) => ta(t) | |
case Right(a) => 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
sealed trait Foo[A] | |
case class Bar[A](a: A) extends Foo[A] | |
case class Baz[A](s: String) extends Foo[A] | |
case class Woozle[A](foo: Foo[A]) extends Foo[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
sealed trait Foo | |
case class Bar(a: Int) extends Foo | |
case class Baz(b: String) extends Foo | |
val barCodec: Codec[Bar] = ??? | |
val bazCodec: Codec[Baz] = ??? | |
val fooCodec: Codec[Foo] = | |
discriminated[Foo] | |
.by(uint32) |
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
case class Path(path: String) extends AnyVal | |
trait QueryValue[U, A] { | |
def param(u: U): A | |
def function(path: Path, args: List[A]): A | |
def nul: A | |
} | |
trait QueryComparison[U, 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
sealed trait QueryValue[A] | |
case class Parameter[A](value: A) extends QueryValue[A] | |
case class Function[A](path: Path, args: List[QueryValue[A]]) extends QueryValue[A] | |
case class Null[A]() extends QueryValue[A] | |
sealed trait QueryComparison[A] | |
case class QueryEqual[A](left: QueryValue[A], right: QueryValue[A]) extends QueryComparison[A] | |
case class QueryGreaterThan[A](left: QueryValue[A], right: QueryValue[A]) extends QueryComparison[A] | |
case class QueryGreaterThanOrEqual[A](left: QueryValue[A], right: QueryValue[A]) extends QueryComparison[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
id | name | album | artist | year | |
--------------------------------------+---------------------------------------------------------------------+----------------------------------------------------+------------------------------------+--------- | |
ebada1a7-fe44-48a6-b5af-178a6b74a88c | China Town | Revenge Of Shinobi | Yuzo Koshiro | 1989 | |
c4f5fe57-e761-40eb-93ed-91df1adcf249 | Sugar Sweet Nightmare | Bakemonogatari: Ongaku Zenshuu Songs & Soundtracks | Yui Horie | 2011 | |
dac75046-fee7-4416-a9f3-c892f72da44c | Hidamari no Uta (ft. Hatsune Miku) | Solitude Freak | Yuyoyuppe | |
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
case class Foo(a: Int) | |
implicit val fooMeta: Meta[Foo] = valueClassMeta[Foo].apply | |
private def valueClassMeta[A]: PartiallyAppliedValueClassMeta[A] = new PartiallyAppliedValueClassMeta[A] | |
private class PartiallyAppliedValueClassMeta[A] { | |
def apply[L <: HList, S]( | |
implicit ev: Generic.Aux[A, L], | |
toL: (S :: HNil) =:= L, |
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
(uuid.successNel[CannotSaveSongError] |@| | |
section.lookupOneOf(songNameKeys).map(SongName(_)).toSuccess(MissingKey(songSection, songNameKeys)).toValidationNel |@| | |
section.lookupOneOf(artistKeys).map(Artist(_)).successNel |@| | |
section.lookupOneOf(albumKeys).map(Album(_)).successNel |@| | |
section.lookupOneOf(genreKeys).map(Genre(_)).successNel |@| | |
section.lookupOneOf(charterKeys).map(Charter(_)).successNel |@| | |
section.lookupOneOf(yearKeys).map(Year(_)).successNel |@| | |
now.successNel |@| | |
now.successNel)(Song.apply _) |
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 instances { | |
implicit val accessTokenDbIdentifiable: DbIdentifiable.Aux[AccessToken, AccessTokens] = | |
new DbIdentifiable.Aux[AccessToken, AcessTokens] { | |
val table = TableQuery[AccessTokens] | |
def getDbId(accessToken: AccessToken): Long = AccessToken | |
def withItemId(item: AccessToken, id: Long): AccessToken = item.copy(id = Option(id)) | |
} | |
implicit val characterDbIdentifiable: DbIdentifiable.Aux[Character, Characters] = | |
new DbIdentifiable.Aux[Character, Characters] { |