forked from chuwy/otus-bats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b71c043
Showing
16 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.bsp/ | ||
target/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Version 0.1.0 (2021-MM-DD) | ||
-------------------------- | ||
Initial release |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2020 Anton Parkhomenko <[email protected]> | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# otus-bats | ||
|
||
## Quickstart | ||
|
||
```bash | ||
$ sbt assembly | ||
``` | ||
|
||
## Copyright and License | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2021 Anton Parkhomenko <[email protected]> | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. | ||
|
||
[license]: http://www.wtfpl.net/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
lazy val root = project.in(file(".")) | ||
.settings( | ||
name := "otusbats", | ||
version := "0.1.0-rc1", | ||
organization := "me.chuwy", | ||
scalaVersion := "2.13.5" | ||
) | ||
.settings(BuildSettings.buildSettings) | ||
.settings(BuildSettings.scalifySettings) | ||
.settings(libraryDependencies ++= Dependencies.all) | ||
.settings(BuildSettings.helpersSettings) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SBT | ||
import sbt._ | ||
import Keys._ | ||
|
||
/** | ||
* To enable any of these you need to explicitly add Settings value to build.sbt | ||
*/ | ||
object BuildSettings { | ||
|
||
// Makes package (build) metadata available withing source code | ||
lazy val scalifySettings = Seq( | ||
sourceGenerators in Compile += Def.task { | ||
val file = (sourceManaged in Compile).value / "settings.scala" | ||
IO.write(file, """package me.chuwy.otusbats.generated | ||
|object ProjectMetadata { | ||
| val version = "%s" | ||
| val name = "%s" | ||
| val organization = "%s" | ||
| val scalaVersion = "%s" | ||
|} | ||
|""".stripMargin.format(version.value, name.value, organization.value, scalaVersion.value)) | ||
Seq(file) | ||
}.taskValue | ||
) | ||
|
||
lazy val buildSettings = Seq[Setting[_]]( | ||
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.0" cross CrossVersion.full) | ||
) | ||
|
||
|
||
lazy val helpersSettings = Seq[Setting[_]]( | ||
initialCommands := "import me.chuwy.otusbats._" | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
|
||
object V { | ||
// Scala | ||
val circe = "0.13.0" | ||
val http4s = "0.21.13" | ||
// Scala (test only) | ||
val specs2 = "4.10.5" | ||
val scalaCheck = "1.15.1" | ||
} | ||
|
||
// Scala | ||
val all = List( | ||
"io.circe" %% "circe-parser" % V.circe, | ||
"org.http4s" %% "http4s-dsl" % V.http4s, | ||
|
||
"org.specs2" %% "specs2-core" % V.specs2 % Test, | ||
"org.specs2" %% "specs2-scalacheck" % V.specs2 % Test, | ||
"org.scalacheck" %% "scalacheck" % V.scalaCheck % Test | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.4.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.16") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.chuwy.otusbats | ||
|
||
import cats.Show | ||
import cats.implicits._ | ||
|
||
object Example { | ||
|
||
def example[A: Show, B: Show](a: A, b: B) = | ||
show"A is $a, B is $b" | ||
|
||
def example[A, B](implicit eva: Show[A], evb: Show[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package me.chuwy.otusbats | ||
|
||
import cats.Mo | ||
|
||
trait Functor[F[_]] { | ||
def map[A, B](fa: F[A])(f: A => B): F[B] | ||
} | ||
|
||
object Functor { | ||
// 1. Instances | ||
implicit val optionFunctor: Functor[Option] = | ||
new Functor[Option] { | ||
def map[A, B](fa: Option[A])(f: A => B): Option[B] = | ||
fa match { | ||
case Some(value) => Some(f(value)) | ||
case None => None | ||
} | ||
} | ||
|
||
implicit val listFunctor: Functor[List] = | ||
new Functor[List] { | ||
def map[A, B](fa: List[A])(f: A => B): List[B] = | ||
fa.map(f) | ||
} | ||
|
||
val e: Either[String, Int] = Right(3) | ||
|
||
val a: Option[Int] = ??? | ||
|
||
// val list = List(Some(1), None, Some(3)) | ||
// list.map { option => option.map(f) } | ||
// nested(list)(i => i.toString) | ||
|
||
def apply[F[_]](implicit ev: Functor[F]): Functor[F] = ev | ||
|
||
// 2. Combinators | ||
|
||
def nested[F[_]: Functor, G[_]: Functor, A, B](fga: F[G[A]])(f: A => B): F[G[B]] = | ||
Functor[F].map(fga) { ga => | ||
Functor[G].map(ga)(f) | ||
} | ||
|
||
case class NeFunctor[A](a: A, counter: Int) { | ||
def map[B](f: A => B): NeFunctor[B] = | ||
NeFunctor(f(a), counter + 1) | ||
} | ||
|
||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.chuwy.otusbats | ||
|
||
trait Monad[F[_]] extends Functor[F] { self => | ||
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] | ||
|
||
def point[A](a: A): F[A] | ||
|
||
def flatten[A](fa: F[F[A]]): F[A] | ||
} | ||
|
||
object Monad { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package me.chuwy.otusbats | ||
|
||
trait Monoid[A] extends Semigroup[A] { | ||
def zero: A | ||
} | ||
|
||
object Monoid { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.chuwy.otusbats | ||
|
||
trait Order[A] { | ||
def compare(x: A, y: A): Option[Boolean] | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package me.chuwy.otusbats | ||
|
||
trait Semigroup[A] { | ||
def combine(x: A, y: A): A | ||
} | ||
|
||
object Semigroup { | ||
|
||
implicit val semigroupInt = new Semigroup[Int] { | ||
override def combine(x: Int, y: Int): Int = x + y | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.chuwy.otusbats | ||
|
||
|
||
trait Show[A] { | ||
def show(a: A): String | ||
} | ||
|
||
object Show { | ||
|
||
// 1.1 Instances | ||
|
||
implicit val stringShow: Show[String] = | ||
new Show[String] { | ||
def show(a: String): String = a | ||
} | ||
|
||
implicit val intShow: Show[Int] = | ||
new Show[Int] { | ||
def show(a: Int): String = a.toString | ||
} | ||
|
||
|
||
// 1.2 Instances with conditional implicit | ||
|
||
implicit def listShow[A](implicit ev: Show[A]): Show[List[A]] = | ||
new Show[List[A]] { | ||
def show(as: List[A]): String = "[" ++ as.map(a => ev.show(a)).mkString(",") ++ "]" | ||
} | ||
|
||
|
||
// 2. Summoner | ||
|
||
def apply[A](implicit ev: Show[A]): Show[A] = ev | ||
|
||
// 3. Syntax extensions | ||
|
||
implicit class ShowOps[A](a: A) { | ||
def show(implicit ev: Show[A]): String = | ||
ev.show(a) | ||
} | ||
|
||
// 4. Helper constructors | ||
|
||
} |