Skip to content

Commit

Permalink
Clarify docs, provide published coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
makkarpov committed Nov 25, 2023
1 parent e00cba0 commit 05ec3c9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ explicits

A tiny library which gives macro authors much more control over Scala 3 implicit resolution process.

```scala
libraryDependencies += "mx.m-k" %% "explicits" % "0.1"
```

Implicit resolution
-------------------

Expand Down Expand Up @@ -39,21 +43,23 @@ def deriveMeow[T](using Type[T], Quotes): Expr[CanMeow[T]] = {
// provide explicit givens:
.give[CanMeow[Foobar]]('{ ??? })
// setup the assisted resolution:
.assist(tpe => isCanMeowType(tpe))
// get the final result:
.search()
.assist {
case '[ CanMeow[t] ] => true // sure, everything can meow with me
case _ => false // can't assist with anything else
}
.search() // get the final result
.toSuccess // aborts the macro if search failed

// inspect and derive what was missing:
val meows: Seq[Expr[?]] = success
.missingTypes
.map {
case '[ CanMeow[t] ] =>
'{ new CanMeow[t] { /* teach `t` to meow here */ } }
}

r match {
case success: ImplicitSearch.Success =>
// inspect what was missing:
val meows: Seq[Expr[?]] = success.missingTypes.map(deriveMeow)

// construct the final expression:
success.construct(meows)

case failure: ImplicitSearch.Failure =>
quotes.reflect.report.errorAndAbort(failure.explanation)
}
// construct the final expression:
success.construct(meows)
}
```

Expand Down
33 changes: 31 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.nio.file.{Files, StandardCopyOption}

ThisBuild / organization := "mx.m-k"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / version := "0.1"
ThisBuild / scalaVersion := "3.2.0"

ThisBuild / idePackagePrefix := Some("mx.mk.explicits")
Expand All @@ -12,6 +12,34 @@ lazy val root = (project in file("."))
.settings(
name := "explicits",

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},

publishMavenStyle := true,

versionScheme := Some("semver-spec"),
licenses := Seq("Apache 2" -> url("https://www.apache.org/licenses/LICENSE-2.0.txt")),
homepage := Some(url("https://github.com/makkarpov/explicits")),
organizationName := "Maxim Karpov",
organizationHomepage := Some(url("https://github.com/makkarpov")),
scmInfo := Some(ScmInfo(
browseUrl = url("https://github.com/makkarpov/explicits"),
connection = "scm:git://github.com/makkarpov/explicits.git"
)),

pomExtra := {
<developers>
<developer>
<id>makkarpov</id>
<name>Maxim Karpov</name>
<url>https://github.com/makkarpov</url>
</developer>
</developers>
},

// i'm too lazy to merge them all + impls don't contain any useful docs or sources
Compile / packageSrc := (generic / Compile / packageSrc).value,
Compile / packageDoc := (generic / Compile / packageDoc).value,
Expand All @@ -31,7 +59,8 @@ lazy val root = (project in file("."))

val subprojectSettings = Seq(
publishArtifact := false,
publishTo := None
publishTo := None,
publish / skip := true
)

val compilerImplSettings = subprojectSettings ++ Seq(
Expand Down

0 comments on commit 05ec3c9

Please sign in to comment.