This file contains hidden or 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 kc.datomic | |
"Datomic utility functions | |
Usage Notes: | |
Some functions in this namespace take sequences of facts and return them modified in some way. Some up-front modifications are useful for those functions, like replacing all map-form facts with vector-form facts. In order to avoid doing these modifications repeatedly to same the same set of facts (which would be harmless but wasteful), two versions of these functions exist: a \"safe\" version that does those up-front modifications, and an \"unsafe\" version that expects those modifications to already have been performed. The unsafe versions are named like the safe ones, but with a single quote appended. | |
TODO: | |
- consider implementing all fns that branch based on operation as multimethods | |
These fns mostly support :db/add, :db/retract :db.fn/retractEntity, :db.fn/cas, |
This file contains hidden or 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 world.core | |
(:require [clojure.core.async :refer [go chan >! <! <!! put! timeout close!]])) | |
(defn apply-to-fsm | |
[[state _] event] | |
(case [state event] | |
[:init :create] [:running [:allocate :run]] | |
[:running :stop] [:stopped [:stop]] | |
[:running :start] [:running []] |
This file contains hidden or 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
;; claj's solution to Reverse Interleave | |
;; https://4clojure.com/problem/43 | |
(fn [a b] (map #(take-nth b (drop % a)) (range b))) |
This file contains hidden or 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
;; claj's solution to Set Intersection | |
;; https://4clojure.com/problem/81 | |
(fn [a b] (set (filter a b))) |
This file contains hidden or 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
;; claj's solution to Anagram Finder | |
;; https://4clojure.com/problem/77 | |
(fn [a] | |
(set | |
(map set | |
(filter #(< 1 (count %)) | |
(vals | |
(group-by | |
(fn [b] (reduce conj #{} b)) |
This file contains hidden or 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 '[noir.server :as server]) | |
(use 'noir.core 'aleph.http 'lamina.core) | |
(defn async-response [response-channel request] | |
(enqueue response-channel | |
{:status 200 | |
:headers {"content-type" "text/plain"} | |
:body "async response"})) | |
(defpage "/" [] "hey from Noir!") |