Liking cljdoc? Tell your friends :D

active.clojure.sum-type


define-sum-typecljmacro

(define-sum-type type-name predicate type-symbols)
source

matchcljmacro

(match sum-type arg & clauses)

Takes a sum-type, a argument and a list of clauses, and expands it to a cond form. sum-type is a type identifier, as defined by define-sum-type. arg is the argument to be matched upon. clauses are pairs of conditions and bodies, e.g.:

(match rgb-color a red? "red" (make-green a) (str "Green with " a) blue? "blue")

There is also a default clause, denoted by the keyword :default as the condition.

This macro throws at compile time if (ordered):

  • sum-type is no symbol
  • sum-type doesn't resolve to a sum-type
  • an uneven number of clauses is passed
  • conditions contain a non-related function, that is, not a predicate or constructor of the passed sum-type in sum-type.
  • The matching is not exhaustive, i.e. a particular predicate/constrcutor is missing.

The resulting form throws at runtime if the passed argument is not of type sum-type

Takes a sum-type, a argument and a list of clauses, and expands it to a cond form.
`sum-type` is a type identifier, as defined by `define-sum-type`.
`arg` is the argument to be matched upon.
`clauses` are pairs of conditions and bodies, e.g.:

`(match rgb-color a
    red? "red"
    (make-green a) (str "Green with " a)
    blue? "blue")
`

There is also a default clause, denoted by the keyword `:default` as the condition.

This macro throws at compile time if (ordered):
- `sum-type` is no symbol
- `sum-type` doesn't resolve to a sum-type
- an uneven number of clauses is passed
- conditions contain a non-related function, that is, not a predicate or constructor of
  the passed sum-type in `sum-type`.
- The matching is not exhaustive, i.e. a particular predicate/constrcutor is missing.

The resulting form throws at runtime if the passed argument is not of type `sum-type`
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close