Skip to content

Commit

Permalink
Merge pull request #5 from julianpeeters/dev
Browse files Browse the repository at this point in the history
Refactor build.sbt, and Fix `ap` method in `ApplicativeOf` `destructured-cats`
  • Loading branch information
julianpeeters committed Dec 16, 2023
2 parents bd63029 + 2b4d82c commit 3bbed35
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 48 deletions.
40 changes: 30 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,52 @@ inThisBuild(List(
versionScheme := Some("semver-spec"),
))

lazy val root = project.in(file(".")).aggregate(tests)
lazy val root = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("."))
.aggregate(cats, scala)
.enablePlugins(NoPublishPlugin)
.jsSettings(test := {})
.nativeSettings(test := {})
.settings(test :=
Def.sequential(
(cats.jvm / Test / test),
(scala.jvm / Test / test)
).value
)

lazy val cats = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/cats"))
.settings(
name := "destructured-cats",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0"
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.scalameta" %%% "munit" % "0.7.29" % Test
)
)
.jsSettings(test := {})
.nativeSettings(test := {})


lazy val scala = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/scala"))
.settings(
name := "destructured-scala",
)

lazy val tests = project.in(file("modules/tests"))
.settings(
name := "destructured-tests",
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "0.7.29" % Test
"org.scalameta" %%% "munit" % "0.7.29" % Test
)
)
.dependsOn(cats.jvm, scala.jvm)
.enablePlugins(NoPublishPlugin)
.jsSettings(test := {})
.nativeSettings(test := {})

// lazy val tests = project.in(file("modules/tests"))
// .settings(
// name := "destructured-tests",
// libraryDependencies ++= Seq(
// "org.scalameta" %% "munit" % "0.7.29" % Test
// )
// )
// .dependsOn(cats.jvm, scala.jvm)
// .enablePlugins(NoPublishPlugin)

lazy val docs = project.in(file("docs/gitignored"))
.settings(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package destructured.cats
import munit.FunSuite

class ApplicativeSuite extends FunSuite:

test("ap 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).ap[Int, String](Some(_ => "foo"))(a)
val expected: Option[String] = Some("foo")
assertEquals(obtained, expected)

test("ap Some[A]"):
val a: Some[Int] = Some(1)
def f[A](a: A)(using A: ApplicativeOf[A]): ApplicativeOf[A] = A
val obtained: Option[String] = f(a).ap[Int, String](Some(_ => "foo"))(a)
val expected: Option[String] = Some("foo")
assertEquals(obtained, expected)

test("ap None.type"):
val a: None.type = None
def f[A](a: A)(using A: ApplicativeOf[A]): ApplicativeOf[A] = A
val obtained: Option[String] = f(a).ap[Int, String](Some(_ => "foo"))(a)
val expected: Option[String] = None
assertEquals(obtained, expected)

test("pure 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)

test("pure Some[A]"):
val a: Some[Int] = Some(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)

test("pure None.type"):
val a: None.type = None
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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@ package destructured.cats
import cats.Applicative

trait ApplicativeOf[FT]:
def pure[A](x: A): Pure[FT, A]
def ap[A, B](ff: Option[A => B])(fa: Option[A]): Ret[FT, B]
def pure[A](x: A): Ret[FT, A]

type Pure[X, A] = X match
type Ret[X, A] = X match
case Option[a] => Option[A]

given [T](using A: Applicative[Option]): ApplicativeOf[Option[T]] =
new ApplicativeOf[Option[T]]:
def pure[A](x: A): Pure[Option[T], A] =
def ap[A, B](ff: Option[A => B])(fa: Option[A]): Ret[Option[T], B] =
A.ap(ff)(fa)
def pure[A](x: A): Ret[Option[T], A] =
A.pure(x)

given [T](using A: Applicative[Option]): ApplicativeOf[Some[T]] =
new ApplicativeOf[Some[T]]:
def pure[A](x: A): Pure[Some[T], A] =
def ap[A, B](ff: Option[A => B])(fa: Option[A]): Ret[Some[T], B] =
A.ap(ff)(fa)
def pure[A](x: A): Ret[Some[T], A] =
A.pure(x)

given (using A: Applicative[Option]): ApplicativeOf[None.type] =
new ApplicativeOf[None.type]:
def pure[A](x: A): Pure[None.type, A] =
def ap[A, B](ff: Option[A => B])(fa: Option[A]): Ret[None.type, B] =
A.ap(ff)(fa)
def pure[A](x: A): Ret[None.type, A] =
A.pure(x)
8 changes: 0 additions & 8 deletions modules/core/shared/src/main/scala/destructured/type.scala

This file was deleted.

This file was deleted.

0 comments on commit 3bbed35

Please sign in to comment.