From 7d83d1f204d08077a8d9946d7c69084d46b0bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fromentin?= Date: Tue, 13 Feb 2024 11:23:54 +0100 Subject: [PATCH] docs: Add "Refining first order types" section --- docs/_docs/reference/refinement.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/_docs/reference/refinement.md b/docs/_docs/reference/refinement.md index 5176236b..286ac8c1 100644 --- a/docs/_docs/reference/refinement.md +++ b/docs/_docs/reference/refinement.md @@ -245,6 +245,17 @@ createUser("Iltotore", "abc123 ") //Left("Your password should be alphanumeric" Note: Accumulative versions exist for [Cats](../modules/cats.md) and [ZIO](../modules/zio.md). +### Refining first order types + +Iron provides utility methods to easily refine first order types (e.g container types like `List`, `Future`, `IO`...). + +```scala +List(1, 2, 3).refineAllUnsafe[Positive] //List(1, 2, 3): List[Int :| Positive] +List(1, 2, -3).refineAllUnsafe[Positive] //IllegalArgumentException +``` + +Variants exist for `Option/Either`, `assume`, `...Further` as well as `RefinedTypeOps` constructors. + ## Assuming constraints Sometimes, you know that your value always passes (possibly at runtime) a constraint. For example: