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
(use 'clojure.algo.monads) | |
(def parser-m (state-t maybe-m)) | |
(defmacro parserfn [& body] | |
`(domonad parser-m ~@body)) | |
(with-monad parser-m | |
(defn optional [p] (m-plus p (m-result nil))) | |
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
;; For every map, if value for :a is even, increment :b's value. Otherwise, increment all values. | |
(update [ALL (if-path [:a even?] :b [ALL LAST])] | |
inc | |
[{:a 2 :b 3 :c 4} | |
{:a 1 :b 10 :d 5 :e 6} | |
{:a 2 :b 0} | |
{:a -1 :f 100}]) | |
==> | |
[{:c 4, :b 4, :a 2} |
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
(def world | |
{:people [{:money 129827 :name "Alice Brown"} | |
{:money 100 :name "John Smith"} | |
{:money 6821212339 :name "Donald Trump"} | |
{:money 2870 :name "Charlie Johnson"} | |
{:money 8273821 :name "Charlie Rose"} | |
] | |
:bank {:funds 4782328748273}} | |
) |
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
(defprotocol TestProtocol | |
(tester [o])) | |
(def tester-with-meta (with-meta tester {:a 1})) | |
(extend-protocol TestProtocol | |
String | |
(tester [o] (println "Strings work!"))) | |
(tester-with-meta "A") ;; Error |
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
(defprotocol TestProtocol | |
(tester [o])) | |
(let [t tester] | |
(defn another-tester [o] | |
(t o))) | |
(def another-tester2 tester) | |
(extend-protocol TestProtocol |
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
(w/defbufferop sum-stats [tuples] | |
[(rest (reduce (fn [[id-old & vals-old :as old] [id & vals]] | |
(if (= id-old id) | |
old | |
(cons id (map + vals-old vals)))) | |
tuples))])) |
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
import cascading.flow.FlowProcess; | |
import cascading.flow.hadoop.HadoopFlowProcess; | |
import cascading.operation.FunctionCall; | |
import cascading.operation.OperationCall; | |
import cascading.tuple.Tuple; | |
import java.util.Random; | |
import cascalog.CascalogFunction; | |
public class RandInt extends CascalogFunction { | |
long _seed; |
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
;; Source: | |
(defmacro binder [& body] | |
(let [[tobind lexpr] (split-at (dec (count body)) body) | |
binded (vec (mapcat (fn [e] | |
(if (and (list? e) (= 'bind (first e))) | |
[(second e) (last e)] | |
['_ e] | |
)) | |
tobind ))] | |
`(let ~binded |
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
(def average | |
(<- [!val :> !avg]) | |
(c/count !count) | |
(c/sum !val :> !sum) | |
(div !sum !count :> !avg)) |
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
(-invoke [this p01 p02 p03 p04 p05 p06 p07 p08 p09 p10 | |
p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 | |
rest] | |
(let [a (object-array | |
(concat | |
[p01 p02 p03 p04 p05 p06 p07 p08 p09 p10 | |
p11 p12 p13 p14 p15 p16 p17 p18 p19 p20] | |
rest))] | |
(com.rpl.specter.impl/bind-params* this a 0)) | |
) |
OlderNewer