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.
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 favila.datomic-util.restore-datoms | |
"A \"manual\" datomic database restore. | |
Writes raw datoms (stored in a stream written by d/datoms) to an empty database. | |
Useful for memory databases: you can write out all the datoms in it, then read | |
them into another database. (Note mem dbs have no log or retractions)." | |
(:require [datomic.api :as d] | |
[clojure.edn :as edn])) | |
(defrecord datom [e a v tx added?]) |
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 '[datomic.api :as d] | |
'[clojure.string :as str]) | |
(defn normalize-query | |
"Turns a vector formatted Datomic datalog query into a map formatted | |
one." | |
[query] | |
(let [pairs (partition-by keyword? query)] | |
(assert (even? (count pairs))) | |
(into |
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
#! /usr/bin/env stack | |
-- stack --resolver lts-18.8 script | |
{-# LANGUAGE OverloadedStrings #-} | |
{- | |
This is a handy illustration of converting between five of the commonly-used | |
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy | |
Text). |