Inspired by "Parsing CSS with Parsec".
Just quick notes and code that you can play with in REPL.
By @kachayev
(ns app | |
"Full stack, multiplayer todo list app in one file" | |
(:require [datascript.core :as d] | |
[hyperfiddle.photon :as p] | |
[hyperfiddle.photon-dom :as dom] | |
[hyperfiddle.photon-ui :as ui]) | |
#?(:cljs (:require-macros app))) | |
(defonce !conn #?(:clj (d/create-conn {}) :cljs nil)) |
(defn xf-sort | |
"A sorting transducer. Mostly a syntactic improvement to allow composition of | |
sorting with the standard transducers, but also provides a slight performance | |
increase over transducing, sorting, and then continuing to transduce." | |
([] | |
(xf-sort compare)) | |
([cmp] | |
(fn [rf] | |
(let [temp-list (java.util.ArrayList.)] | |
(fn |
{:db/ident :bsu.fns/reset-to-many-by, | |
:db/doc "Resets the set of entities which are related to `eid` via `ref-attr` to the set given by `val-maps`. | |
Assumptions: | |
* `ref-attr` is a cardinality-many, ref attribute. | |
* `e` is an entity identifier for an _existing_ entity | |
(you have to know whether an entity exists before using this function, | |
and it's pointless to use it on a non-existing entity as opposed to just asserting all the new values.) | |
* `val-maps` is a seq of transaction maps, all of which have the `v-id-attr` key provided. | |
* `retract-target-entity?`: whether to call :db.fn/retractEntity on the old entities which get removed from the relationship. | |
* the old values of the relationship all have the `id-attr` attribute." |
(defmacro datomic-fn | |
"Creates a datomic function given (fn [db e a ...] code...)" | |
[[_ args & body]] | |
`(d/function '{:lang "clojure" | |
:params ~args | |
:code (do ~@body)})) | |
(defn trinity-new | |
"1. If a is a ref: | |
Ensures that |
Inspired by "Parsing CSS with Parsec".
Just quick notes and code that you can play with in REPL.
By @kachayev
Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
# --------------------------------------------------------------------------- | |
# | |
# Description: This file holds all my BASH configurations and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better (remapping defaults and adding functionality) | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Process Management |
(ns myupsert.core | |
(require [datomic.api :as d])) | |
(def schema | |
[ | |
{:db/id #db/id [:db.part/db] | |
:db/ident :product/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} |
;; Datomic example code | |
;; | |
;; The extent of entity ?x is all datoms that are about ?x. | |
;; Drop this into your rules. | |
;; | |
;; Demonstrates | |
;; | |
;; 1. recursive query (extent calls itself) | |
;; 2. disjunction (different extent bodies are ORed) | |
;; 3. component attributes (e.g. your arm is a component, your brother isn't) |