Skip to content

Instantly share code, notes, and snippets.

@erdos
erdos / bcug-2016-11-24.md
Last active November 23, 2016 07:53
BCUG presentation - we dont need no types

Budapest Clojure User Group - meetup presentation proposal for 2016-11-24

Schema vs. Spec

Validating data in dynamic typed programming languages is an important aspect of making sure our programs are safe and correct. In the short presentation we will take a look at two solutions for validating data in Clojure.

Prismatic Schema is a mature library with simple syntax and strong support in the Clojure ecosystem. The new competitor is core.specs supporting in the core language with promising new features. After the presentation we will discuss personal experiences with the advantages and disadvantages of both solutions.

@erdos
erdos / split-by-key1.clj
Last active November 20, 2016 22:16
split-by-key returning groups may not cover whole input
(do
;; number of groups
(def n (.availableProcessors (Runtime/getRuntime)))
;; memoized round-robin style group number generator for items
(let [a (atom (cycle (range n)))]
(def get-id-for
(memoize (fn [_] (first (swap! a next))))))
(defn split-by-key
(ns roman-nums.core
(:require
[clojure.test :refer [testing are]]))
(def ^:private roman-digits
[[1000 "M"] [900 "CM"]
[500 "D"] [400 "CD"]
[100 "C"] [90 "XC"]
[50 "L"] [40 "XL"]
[10 "X"] [9 "IX"]