(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
<html> | |
<body> | |
<pre id="output"></pre> | |
<script src="//cdn.jsdelivr.net/jquery/2.1.1/jquery.js"></script> | |
<script> | |
var $output = $('#output'); | |
var db = openDatabase('fts_demo', 1, 'fts_demo', 5000000); | |
db.transaction(function (tx){ |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
# build with | |
# docker build -t 'necrobious/haskell-ghc-7.8-64' . | |
FROM ubuntu:14.04 | |
MAINTAINER necrobious@gmail.com | |
ENV DEBIAN_FRONTEND noninteractive | |
####### Install Dependencies ################################################### | |
RUN apt-get -y update |
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.
angular.module('myApp').factory('httpLoaderInterceptor', ['$rootScope', function($rootScope) { | |
// Active request count | |
var requestCount = 0; | |
function startRequest(config) { | |
// If no request ongoing, then broadcast start event | |
if( !requestCount ) { | |
$rootScope.$broadcast('httpLoaderStart'); | |
} |
; it's a bit cumbersome to set up and there's the unfortunate need to ignore the tag | |
; in the individual methods, but this allows you to leave the interpretation of open | |
; variants, well, *open* for extension by multimethod. | |
; dispatch off the first argument, which will be the tag | |
(defmethod command-multi (fn [tag & data] tag)) | |
; the first argument to the *method* is still the tag | |
(defmulti command-multi :print [_ val] (println val)) | |
(defmulti command-multi :read [_ fname] (slurp fname)) |
(ns variant | |
(:require [clojure.core.typed :as t])) | |
(t/defalias V | |
(t/Rec [V] | |
(t/U '[':lambda t/Sym V] | |
'[':if V V V] | |
'[':val t/Any]))) | |
(t/ann command [V -> t/Str]) |
(defmacro defvariant | |
[name [[tag & variant-binders] & other-binders] body] | |
`(defmethod ~name ~tag [[_# ~@variant-binders] | |
~@other-binders] | |
~body) | |
[name [tag & binders] body] | |
`(defmethod ~name ~tag [[_# ~@binders]] ~body)) | |
; CompilerException java.lang.RuntimeException: Unable to resolve symbol: & in this context, compiling:(/tmp/form-init8620656005427572977.clj:1:1) |
(ns variants-playground.core | |
(:require [clojure.core.typed :as t :refer [cf defalias ann U Value Str HVec HMap]] | |
[clojure.core.match :refer [match]])) | |
(defmacro Variant [& lst] | |
`(U ~@(for [[tag & items] lst] | |
`(HVec [(Value ~tag) | |
(HMap :mandatory ~@items)])))) | |
(println (macroexpand '(Variant [:foo {:bar Str}]))) |
;; ; made this macro scraching my head between the simplicity of Haskell for fix | |
;; ; and the absence of curryfication in Clojure. | |
;; (P expr-fn) ; makes expr-fn lazy | |
;; (P P expr-fn) ; curry one time expr-fn | |
;; (P P P expr-fn) ; curry two time expr-fn | |
;; (= ((((P P P str) "a") "b") "c") "abc") ;=> true | |
(defmacro P [& f] | |
(let [x (gensym 'x)] ;; cannot be replaced by x# due to nested macro expansion. |