From da8629d18e3a269f5a95cb0863a3b47e3944d4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fromentin?= <42907886+Iltotore@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:01:35 +0200 Subject: [PATCH] feat: Add Pure alias for True (#149) --- docs/_docs/reference/newtypes.md | 9 +++++++++ main/src/io/github/iltotore/iron/constraint/any.scala | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/docs/_docs/reference/newtypes.md b/docs/_docs/reference/newtypes.md index fc786651..74d41fe7 100644 --- a/docs/_docs/reference/newtypes.md +++ b/docs/_docs/reference/newtypes.md @@ -94,3 +94,12 @@ val unsafeRuntime: Double = else throw new IllegalArgumentException("...") ``` +## New type with no constraint + +You can create a new type without restriction by using the [[Pure|io.github.iltotore.iron.constraint.any.Pure]] +constraint. [[Pure|io.github.iltotore.iron.constraint.any.Pure]] is an alias for +[[True|io.github.iltotore.iron.constraint.any.True]], a constraint that is always satisfied. + +```scala +type FirstName = String :| Pure +``` \ No newline at end of file diff --git a/main/src/io/github/iltotore/iron/constraint/any.scala b/main/src/io/github/iltotore/iron/constraint/any.scala index b388f55a..55b5321d 100644 --- a/main/src/io/github/iltotore/iron/constraint/any.scala +++ b/main/src/io/github/iltotore/iron/constraint/any.scala @@ -18,6 +18,12 @@ object any: */ final class True + /** + * Alias for [[True]]. Usually used for new types with no constraint. + * @see "Creating new types" reference. + */ + type Pure = True + /** * An always-invalid constraint. */