项目作者: helins

项目描述 :
About void and absence of information
高级语言: Clojure
项目地址: git://github.com/helins/void.cljc.git
创建时间: 2018-01-28T14:50:39Z
项目社区:https://github.com/helins/void.cljc

开源协议:Mozilla Public License 2.0

下载


Void, about handling nil

Clojars
Project

Cljdoc

CircleCI

Compatible with Clojurescript.

Nil is an information representing the absence of information.

This leads to puzzling shenanigans:

  1. ;; This is an empty collection, a perfectly normal phenomenon:
  2. []
  3. ;; It contains nothing.
  4. ;; This is a collection containing something that is nothing:
  5. [nil]
  6. ;; Sometimes it is not what we want.
  7. ;; This is a map containing something that is nothing, nowhere:
  8. {nil nil}
  9. ;; This is seldom what we want.

This small library proposes macros and functions for interacting with nil under
various circumstances. Most notably, it considers that nothing is nothing as the
following few examples demonstrate.

Usage

Meditate and reflect on the full API.

Some Socratic excerpts :

  1. (require '[helins.void :as void])
  2. (= (void/assoc {:a 42}
  3. :a nil
  4. :b 42)
  5. {:a 42
  6. :b 42})
  7. (= (void/update {:a 42
  8. :b 42}
  9. :b
  10. (fn [x]
  11. nil))
  12. {:a 42})
  13. (= (void/dissoc-in {:a {:b {:c {:d 42}}
  14. :e 42}}
  15. [:a :b :c :d])
  16. {:a {:e 42}})
  17. (= (void/update-in {:a {:b {:c {:d 24}}
  18. :e 42}}
  19. [:a :b :c :d]
  20. (fn [x]
  21. (when (= x
  22. 42)
  23. x)))
  24. {:a {:e 42}})
  25. (= (void/merge {:a 42
  26. :b 42}
  27. {:b nil
  28. :c 42})
  29. {:a 42
  30. :c 42})
  31. (= (void/dmerge {:a {:b {:c {:d 42}}
  32. :e 42}}
  33. {:a {:b {:c {:d nil}}
  34. :f 42}})
  35. {:a {:e 42
  36. :f 42}})
  37. (= (void/prune {:a 42
  38. :b {:c 42
  39. :d nil
  40. :e {:f {:g nil}}}})
  41. {:a 42
  42. :b {:c 42}})

" class="reference-link">Running tests

On the JVM, using Kaocha:

  1. $ ./bin/test/jvm/run
  2. $ ./bin/test/jvm/watch

On NodeJS, using Kaocha-CLJS:

  1. $ ./bin/test/node/run
  2. $ ./bin/test/node/watch

In the browser, using Chui:

  1. $ ./bin/test/browser/compile
  2. # Then open ./resources/chui/index.html
  3. # For testing an advanced build
  4. $ ./bin/test/browser/advanced

" class="reference-link">Development

Starting in Clojure JVM mode, mentioning an additional deps alias (here, a local
setup of NREPL):

  1. $ ./bin/dev/clojure :nrepl

Starting in CLJS mode using Shadow-CLJS:

  1. $ ./bin/dev/cljs
  2. # Then open ./resources/public/index.html

License

Copyright © 2018 Adam Helinski

Licensed under the term of the Mozilla Public License 2.0, see LICENSE.