Skip to content

Commit f4c2863

Browse files
committed
readme
1 parent 03a0d41 commit f4c2863

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -836,19 +836,28 @@ The first argument to `:error/fn` is a map with keys:
836836
- `:schema`, the schema to explain
837837
- `:value` (optional), the value to explain
838838
- `:negated` (optional), a function returning the explanation of `(m/explain [:not schema] value)`.
839-
If provided, then this call explains `(m/explain [:not schema] value)`.
840-
Rarely needed but useful in some cases.
841-
Note in this scenario, `(m/validate schema value)` is true and
842-
the resulting error message will be negated by the `:error/fn` caller in the same way as `:error/message`
843-
in service of a final explanation of `(m/explain [:not schema] value)`:
839+
If provided, then we are explaining the failure of negating this schema via `(m/explain [:not schema] value)`.
840+
Note in this scenario, `(m/validate schema value)` is true.
841+
If returning a string,
842+
the resulting error message will be negated by the `:error/fn` caller in the same way as `:error/message`.
843+
Returning `(negated string)` disables this behavior and `string` is used as the negated error message.
844844
```clojure
845-
;; e.g.,
845+
;; automatic negation
846846
(me/humanize
847847
(m/explain
848848
[:not [:fn {:error/fn {:en (fn [_ _] "should not be a multiple of 3")}}
849849
#(not= 0 (mod % 3))]]
850850
1))
851851
; => ["should be a multiple of 3"]
852+
853+
;; manual negation
854+
(me/humanize
855+
(m/explain [:not [:fn {:error/fn {:en (fn [{:keys [negated]} _]
856+
(if negated
857+
(negated "should not avoid being a multiple of 3")
858+
"should not be a multiple of 3"))}}
859+
#(not= 0 (mod % 3))]] 1))
860+
; => ["should not avoid being a multiple of 3"]
852861
```
853862

854863
Here are some basic examples of `:error/message` and `:error/fn`:

0 commit comments

Comments
 (0)