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
;; 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
(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
isolation.scheduler.machines: | |
"my-topology": 8 | |
"tiny-topology": 1 | |
"some-other-topology": 3 |
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
stream.groupBy(new Fields("val1")) | |
.aggregate(new Fields("val2"), new Sum(), new Fields("sum")) |
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
stream.aggregate(new Fields("val2"), new Sum(), new Fields("sum")) |
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
stream.each(new Fields("x", "y"), new AddAndMultiply(), new Fields("added", "multiplied")); |
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
public class AddAndMultiply extends BaseFunction { | |
public void execute(TridentTuple tuple, TridentCollector collector) { | |
int i1 = tuple.getInteger(0); | |
int i2 = tuple.getInteger(1); | |
collector.emit(new Values(i1 + i2, i1 * i2)); | |
} | |
} |
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
public class MyFilter extends BaseFilter { | |
public boolean isKeep(TridentTuple tuple) { | |
return tuple.getInteger(0) < 10; | |
} | |
} |
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
stream.each(new Fields("y"), new MyFilter()) |