Skip to content
/ sanity Public

Validation of arguments through deducing type from name.

Notifications You must be signed in to change notification settings

MHOOO/sanity

Repository files navigation

Introduction

Sanity is a clojure library which uses plug-in based macros to…

  1. deduce argument types based on argument names
  2. add type hints & assertions based on the former

Furthermore, the plug-in system can be used to enhance any macro you like in various ways.

Installation

You may simply specify the project as a dependency in your projects project.clj using [de.karolski/sanity "0.1.0"].

Alternatively if you want the bleeding edge, clone the repository and use leiningen’s lein install command to install the library into your local maven repo. After that you can use it inside your own local projects by specifying [de.karolski/sanity "0.1.0-SNAPSHOT"] as a dependency.

Usage

Simple example defining a custom defn:

(defpluggable
  defn
  [(argument-type-deducer-plugin :deduce-map {#"i" Long
                                              #".*-fn" clojure.lang.AFunction
                                              #".*text" String
                                              })
   (argument-type-assertion-plugin)
   clojure.core/defn])

Once you have that defined (make sure you (:refer-clojure :exclude [defn]) inside the namespace), you can use it like a normal defn form. However, any argument which matches the regular expressions as specified inside the :deduce-map keyword argument to the argument-type-deducer-plugin will be type hinted and checked upon function entry.

In case you don’t want to completely override defn, you may also use with-pluggable:

(with-pluggable
  defn
  [(argument-type-deducer-plugin :deduce-map {#"i" Long
                                              #".*-fn" clojure.lang.AFunction
                                              #".*text" String
                                              })
   (argument-type-assertion-plugin)
   clojure.core/defn]

  ;; YOUR CODE HERE
  )

This will only bind defn within the local scope of with-pluggable.

Future

see this projects TODO.org

License

Copyright (C) 2011 FIXME

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

About

Validation of arguments through deducing type from name.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published