-
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.
Add ApplicativeOf for Option, CtorOf for Option
- Loading branch information
1 parent
6c09169
commit 63b3aa5
Showing
8 changed files
with
134 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,71 @@ | ||
inThisBuild(List( | ||
crossScalaVersions := Seq(scalaVersion.value), | ||
description := "Typeclasses of a lower kind.", | ||
organization := "com.julianpeeters", | ||
homepage := Some(url("https://github.com/julianpeeters/destructured")), | ||
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), | ||
developers := List( | ||
Developer( | ||
"julianpeeters", | ||
"Julian Peeters", | ||
"julianpeeters@gmail.com", | ||
url("http://github.com/julianpeeters") | ||
) | ||
), | ||
scalacOptions ++= Seq( | ||
"-deprecation", | ||
"-feature", | ||
"-source:future", | ||
"-Werror", | ||
"-Wunused:all", | ||
"-Wvalue-discard", | ||
"-Ykind-projector:underscores" | ||
), | ||
scalaVersion := "3.3.1", | ||
versionScheme := Some("semver-spec"), | ||
)) | ||
|
||
lazy val root = project.in(file(".")).aggregate(tests) | ||
|
||
lazy val cats = crossProject(JSPlatform, JVMPlatform, NativePlatform) | ||
.in(file("modules/cats")) | ||
.settings( | ||
name := "destructured-cats", | ||
libraryDependencies ++= Seq( | ||
"org.typelevel" %%% "cats-core" % "2.10.0" | ||
) | ||
).dependsOn(core) | ||
|
||
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform) | ||
.in(file("modules/core")) | ||
.settings( | ||
name := "destructured-core", | ||
) | ||
|
||
lazy val scala = crossProject(JSPlatform, JVMPlatform, NativePlatform) | ||
.in(file("modules/scala")) | ||
.settings( | ||
name := "destructured-scala", | ||
).dependsOn(core) | ||
|
||
lazy val tests = project.in(file("modules/tests")) | ||
.settings( | ||
name := "destructured-tests", | ||
libraryDependencies ++= Seq( | ||
"org.scalameta" %% "munit" % "0.7.29" % Test | ||
) | ||
) | ||
.dependsOn(cats.jvm, core.jvm, scala.jvm) | ||
.enablePlugins(NoPublishPlugin) | ||
|
||
lazy val docs = project.in(file("docs/gitignored")) | ||
.settings( | ||
mdocOut := file("."), | ||
mdocVariables := Map( | ||
"SCALA" -> crossScalaVersions.value.map(e => e.takeWhile(_ != '.')).mkString(", "), | ||
"VERSION" -> version.value.takeWhile(_ != '+'), | ||
) | ||
) | ||
.dependsOn(cats.jvm, core.jvm, scala.jvm) | ||
.enablePlugins(MdocPlugin) | ||
.enablePlugins(NoPublishPlugin) |
12 changes: 12 additions & 0 deletions
12
modules/cats/shared/src/main/scala/destructured/cats/ApplicativeOf.scala
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 destructured.cats | ||
|
||
import cats.Applicative | ||
import destructured.Destructured | ||
|
||
trait ApplicativeOf[FT]: | ||
def pure[A](x: A): Destructured[FT, A] | ||
|
||
given [T](using A: Applicative[Option]): ApplicativeOf[Option[T]] = | ||
new ApplicativeOf[Option[T]]: | ||
def pure[A](x: A): Destructured[Option[T], A] = | ||
A.pure(x) |
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,4 @@ | ||
package destructured | ||
|
||
type Destructured[X, A] = X match | ||
case Option[a] => Option[A] |
11 changes: 11 additions & 0 deletions
11
modules/scala/shared/src/main/scala/destructured/scala/CtorOf.scala
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,11 @@ | ||
package destructured.scala | ||
|
||
import destructured.Destructured | ||
|
||
trait CtorOf[FT]: | ||
def apply[A](x: A): Destructured[FT, A] | ||
|
||
given [T]: CtorOf[Option[T]] = | ||
new CtorOf[Option[T]]: | ||
def apply[A](x: A): Destructured[Option[T], A] = | ||
Some(x) |
11 changes: 11 additions & 0 deletions
11
modules/tests/src/test/scala/destructured/cats/ApplicativeSuite.scala
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,11 @@ | ||
package destructured.cats | ||
import munit.FunSuite | ||
|
||
class ApplicativeSuite extends FunSuite: | ||
|
||
test("Option[A]"): | ||
val a: Option[Int] = Option(1) | ||
def f[A](a: A)(using A: ApplicativeOf[A]): ApplicativeOf[A] = A | ||
val obtained: Option[String] = f(a).pure("foo") | ||
val expected: Option[String] = Some("foo") | ||
assertEquals(obtained, expected) |
12 changes: 12 additions & 0 deletions
12
modules/tests/src/test/scala/destructured/scala/CtorSuite.scala
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 destructured.scala | ||
|
||
import munit.FunSuite | ||
|
||
class CtorSuite extends FunSuite: | ||
|
||
test("Option[A]"): | ||
val a: Option[Int] = Option(1) | ||
def f[A](a: A)(using A: CtorOf[A]): CtorOf[A] = A | ||
val obtained: Option[String] = f(a)("foo") | ||
val expected: Option[String] = Some("foo") | ||
assertEquals(obtained, expected) |
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.9.8 |
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 @@ | ||
// cross | ||
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") | ||
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0") | ||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16") | ||
|
||
// docs | ||
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.1") | ||
|
||
// publish | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") | ||
addSbtPlugin("org.typelevel" % "sbt-typelevel-no-publish" % "0.6.2") |