Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Clojure type matching module.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .lein-deps-sum
Octocat-spinner-32 .lein-failures
Octocat-spinner-32 README.md
Octocat-spinner-32 project.clj
README.md

TypeMatch

A Clojure type matching library.

Usage

(typematch? :any nil) ;=> true
(typematch? :int 5) ;=> true
(typematch? :pos 42) ;=> true
(typematch? :str "Hello, world.") ;=> true
(typematch? [:int :str] [37 "foo"]) ;=> true
(typematch? [#(> % 5) :str] [10 "bar"]) ;=> true
(typematch? [#(> % 5) :key] [0 :foo]) ;=> false
(typematch? [:any :-> :int] [:bar 1 2 3]) ;=> true
(typematch? [:any :-> :int] [:bar 1 2 \c]) ;=> false

Available Type Keywords

{ :any    "Any type"
  :nil    "Nil"
  :symbol "Symbols"
  :bool   "Booleans"
  :key    "Keywords"
  :num    "Numbers"
  :int    "Integers"
  :zero   "Zero"
  :pos    "Positive Numbers"
  :neg    "Negative Numbers"
  :nat    "Natural Numbers"
  :float  "Floats"
  :ratio  "Ratios"
  :str    "Strings"
  :char   "Characters"
  :reg    "Regular Expressions"
  :vec    "Vectors"
  :seq    "Sequences"
  :set    "Sets"
  :map    "Maps"
  :coll   "Any collection"
  :fn     "Functions" }

Todo

  • Destructure maps and sets.
  • Use sequences for detailed matching (with values).

License

Copyright (C) 2012 Liam Goodacre

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.