Skip to content

Commit

Permalink
Add ApplicativeOf for Option, CtorOf for Option
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpeeters committed Dec 16, 2023
1 parent 6c09169 commit 63b3aa5
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
71 changes: 71 additions & 0 deletions build.sbt
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)
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)
4 changes: 4 additions & 0 deletions modules/core/shared/src/main/scala/destructured/type.scala
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]
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)
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 modules/tests/src/test/scala/destructured/scala/CtorSuite.scala
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)
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.8
12 changes: 12 additions & 0 deletions project/plugins.sbt
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")

0 comments on commit 63b3aa5

Please sign in to comment.