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.3.4
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.3.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.cerst/auto-require_2.12/
implementation 'com.github.cerst:auto-require_2.12:0.3.4'
// https://jarcasting.com/artifacts/com.github.cerst/auto-require_2.12/
implementation ("com.github.cerst:auto-require_2.12:0.3.4")
'com.github.cerst:auto-require_2.12:jar:0.3.4'
<dependency org="com.github.cerst" name="auto-require_2.12" rev="0.3.4">
  <artifact name="auto-require_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.cerst', module='auto-require_2.12', version='0.3.4')
)
libraryDependencies += "com.github.cerst" % "auto-require_2.12" % "0.3.4"
[com.github.cerst/auto-require_2.12 "0.3.4"]

Dependencies

compile (2)

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

provided (1)

Group / Artifact Type Version
com.github.ghik : silencer-lib_2.12.12 jar 1.7.1

test (2)

Group / Artifact Type Version
io.estatico : newtype_2.12 jar 0.4.4
org.scalatest : scalatest_2.12 jar 3.2.1

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.3.4
0.3.3
0.3.2
0.3.0