This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If a predicate is passed to `explain-data` directly (to be used as a spec), then the `spec` value is not a symbol, but the function itself. | |
This makes it tricky to write a consistent printer - I'd like to be able to say "<value> did not match <predicate>" in a consistent way. | |
user=> *clojure-version* | |
{:major 1, :minor 9, :incremental 0, :qualifier "alpha19"} | |
user=> (require '[clojure.spec.alpha :as s]) | |
nil | |
user=> (::s/spec (s/explain-data string? 1)) | |
#object[clojure.core$string_QMARK___4964 0x125290e5 "clojure.core$string_QMARK___4964@125290e5"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Set up instrumentation somewhere in your project | |
;; (only need to do this once) | |
(require '[clojure.core.specs.alpha]) | |
(require '[clojure.spec.alpha :as s]) | |
(require '[clojure.spec.test.alpha :as stest]) | |
(require '[expound.alpha :as expound]) | |
(set! s/*explain-out* expound/printer) | |
(stest/instrument) | |
;;; later on ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cider and Cider nrepl 0.15.0 | |
// In *cider-repl localhost*, the formatted string is correct | |
// because the ^^^ appears right under the value (to highlight the bad value) | |
-- Spec failed -------------------- | |
(... 123) | |
^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I learned this technique from these posts | |
;; http://blog.klipse.tech/clojure/2016/10/10/defn-args.html | |
;; http://blog.klipse.tech/clojure/2016/10/10/defn-args-2.html | |
;; (which has a lot more details!!!) | |
;; You must require this to load the core specs | |
(require '[clojure.core.specs.alpha :as specs]) | |
(require '[clojure.spec.alpha :as s]) | |
(defn my-let* [args] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.spec.alpha :as s]) | |
(require '[expound.alpha :as expound]) | |
;; You'll need to adjust the try/catch error | |
;; classes for Clojure | |
;; sp - the spec name | |
;; v - the value you want to check | |
(if (s/valid? sp v) | |
v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;[org.clojure/clojure "1.9.0-alpha17"] | |
;;[org.clojure/clojurescript "1.9.542"] | |
;;[org.clojure/spec.alpha "0.1.123"] | |
(s/def :foo/user-map (s/map-of string? int?)) | |
(s/explain-data :foo/user-map {"hi" "foo"}) | |
;; Actual value: | |
;; #:cljs.spec.alpha{:problems | |
;; ({:path [1], | |
;; :pred int?, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;[org.clojure/clojure "1.9.0-alpha17"] | |
;;[org.clojure/clojurescript "1.9.542"] | |
;;[org.clojure/spec.alpha "0.1.123"] | |
(s/def :foo.user/name string?) | |
(s/def :foo/user (s/keys :req-un [:foo.user/name])) | |
(s/def :foo/user-map (s/map-of :foo.user/name :foo/user)) | |
(s/explain-data :foo/user-map {"bob" {:age 2 :city "chicago"}}) | |
;; returns the following... | |
(comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; [org.clojure/clojurescript "1.9.229"] | |
(s/def :event/type keyword?) | |
(s/def :search/url string?) | |
(s/def :error/code int?) | |
(defmulti event-type :event/type) | |
(defmethod event-type :event/search [_] | |
(s/keys :req [:event/type :search/url])) | |
(defmethod event-type :event/error [_] | |
(s/keys :req [:event/type :error/code])) | |
(defmethod event-type :default [_] (s/keys)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn render-cell [{:keys [cellname]}] | |
(println "cell-name" cellname) | |
;; Note the key here | |
[:div {:key cellname} | |
[:p cellname]]) | |
;; This version works as expected - if I change | |
;; the second cell, the "println" above only fires for that cell | |
(defn visible-cells [cells] | |
[n/view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns klipse-like.core | |
(:require [reagent.core :as r]) | |
(:import [goog.async Delay])) | |
(enable-console-print!) | |
(defonce !state (r/atom nil)) | |
(defn input* | |
"Like :input, but support on-change-text prop. Avoids mutability pitfalls of |