Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax highlight clojure snippets #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ Require: `[de.otto.nom.core :as nom]`

You can create a nom anomaly using `fail`:

```clojure
(nom/fail ::my-category {:some data})
```

or

```clojure
(nom/fail ::my-category :some data)
```

which both produce the same:

```clojure
[::nom/anomaly ::my-category {:some data}]
```

Our own anomaly format is a bit different from the `cognitect.anomalies` format,
but those are recognized too and automatically adapted. In order to extend this
behaviour to your own anomaly formats, extend the `abominable?` and `adapt`
multimethods using a proper predicate, e. g.:

```clojure
(defn my-anomaly? [x]
...whatever...)

Expand All @@ -54,35 +61,44 @@ multimethods using a proper predicate, e. g.:

(defmethod nom/adapt my-anomaly? [x]
(nom/fail (yaba x) :daba (doo x)))
```

### Propagation

The basic principle is maybe best illustrated by showing `nom`. If you have a
form like this:

```clojure
(foo arg0 arg1)
```

where both `arg0` or `arg1` might be anomalies, then you can prepend `nom`:

```clojure
(nom/nom foo arg0 arg1)
```

which does the same as the form above, but if `arg0` or `arg1` is an anomaly,
then it will immediately return that anomaly and not call `foo` at all.

You can do this in a threading manner very similar to `some->` and `some->>`,
with `nom->` and `nom->>`:

```clojure
(nom/nom-> foo
(bar baz)
quux
(wizzle wozzle))
```

which would be equivalent to:

```clojure
(nom/nom wizzle
(nom/nom quux
(nom/nom bar foo baz))
wozzle)
```

i. e. thread the values just as in `->`, but if any of the intermediate values
is an anomaly, short-circuit and return that anomaly.
Expand All @@ -91,16 +107,20 @@ Another pattern is checking a number of values, then executing a body, but if
any of the values is an anomaly, short-circuit and return the anomaly instead.
That's what `with-nom` is for:

```clojure
(nom/with-nom [something (something else) (and another thing)]
(frob something)
(wozzle another thing))
```

Of course, this begs for binding those values; we have `let-nom>` for that:

```clojure
(nom/let-nom> [a something
b (something else)
c (and another thing)]
(frob a b c))
```

This short-ciruits as soon as an anomaly is encountered in the bindings; in that
case, no further binding nor the body is even evaluated. You might want to have
Expand Down