auto_require


License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

com.github.cerst
ArtifactId

ArtifactId

auto_require_2.12
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

auto_require
auto_require
Project URL

Project URL

https://github.com/cerst/auto_require
Project Organization

Project Organization

Constantin Gerstberger
Source Code Management

Source Code Management

https://github.com/cerst/auto_require

Download auto_require_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.cerst/auto_require_2.12/ -->
<dependency>
    <groupId>com.github.cerst</groupId>
    <artifactId>auto_require_2.12</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.cerst/auto_require_2.12/
implementation 'com.github.cerst:auto_require_2.12:0.2.0'
// https://jarcasting.com/artifacts/com.github.cerst/auto_require_2.12/
implementation ("com.github.cerst:auto_require_2.12:0.2.0")
'com.github.cerst:auto_require_2.12:jar:0.2.0'
<dependency org="com.github.cerst" name="auto_require_2.12" rev="0.2.0">
  <artifact name="auto_require_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.cerst', module='auto_require_2.12', version='0.2.0')
)
libraryDependencies += "com.github.cerst" % "auto_require_2.12" % "0.2.0"
[com.github.cerst/auto_require_2.12 "0.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.10
org.scala-lang : scala-reflect jar 2.12.10

provided (1)

Group / Artifact Type Version
com.github.ghik : silencer-lib_2.12.10 jar 1.4.4

test (2)

Group / Artifact Type Version
io.estatico : newtype_2.12 jar 0.4.3
org.scalatest : scalatest_2.12 jar 3.1.0

Project Modules

There are no modules declared in this project.

GitHub license Maven Central

auto-require

auto_require is a macro implementation of Scala's require that comes with auto-generated error messages.
It has no dependencies other than scala-reflect.

Usage

libraryDependencies ++= Seq(
    "com.github.cerst" %% "auto-require" % autoRequireVersion
)
import com.github.cerst.autorequire._

final case class Person(age: Int, name: String) {
    autoRequire[Person](!(age < 13) && name.nonEmpty)
}

val _ = Person(10, "John")
// Exception in thread "main" [...]: Requirement failed for 'Person': '!(Person.this.age < 13) && scala.Predef.augmentString(Person.this.name).nonEmpty' { Person.this.age = 10, Person.this.name = John }

In order to display the error message above, the macro generates variable declarations for all variables found in the expression.
Whereas you can use autoRequire everywhere, you always need to specify a generic type as the latter is displayed in the error message.
If you prefer not throwing exceptions, you can use autoRequireEither.
There are a few ways to customize the error message. Please check the Scaladoc of com.github.cerst.autorequire.DisplayConfig and its sub-types for more info.

Versions

Version
0.2.0
0.1.0