Git Product home page Git Product logo

like's Introduction

like

A pragmatic approach to type information in Clojure

Dynamic typing is nice, but sometimes I would like to have more type information when the data is complex, or I have not looked at the function for a while. Wouldn't it be nice to have verifiable documention of what data a function needs, and how the result of the function looks like?

This small little function makes code easier to reason about for me. It's called like. It checks the shape of things.

(like [] [1 :keyword '()]) => true

(like [1] [1 2 3]) => true

(like [:keyword] [1 2 3]) => false

(like [{:name "joe" :address ""}] [{:name "me" :address "here"} {:name "you" :address "there"}]) => true

(like {:name "joe" :address ""} {:name "me"}) => false

(like #{1} [1]) => false

You can use it as pre- or postcondition, so the similarity of in/output is succinctly documented and checked automatically. And you do not have to use it everywhere, only where you feel it helps you understand the code better.

(fn parse-int [str] ...)

needs no type or unit-test to be understood.

(fn parse-appointment [str] ...)

is better understood when it has

{:post [(like {:id (UUID.) :name "me" :date (java.util.Date .)} %)]}

like's People

Contributors

toofuu avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.