Skip to content

Instantly share code, notes, and snippets.

@rjeli
Created June 14, 2016 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjeli/c1ca78c099febc60a37289f7089423f5 to your computer and use it in GitHub Desktop.
Save rjeli/c1ca78c099febc60a37289f7089423f5 to your computer and use it in GitHub Desktop.
dumb
private class CountingLogger<T> implements Function<T, T> {
private int every;
private int count;
private Function<Integer,String> message;
public CountingLogger(int every, Function<Integer,String> message) {
this.every = every;
this.message = message;
this.count = 0;
}
@Override
public T apply(T t) {
if (count++ % every == 0) {
info(message.apply(count));
}
return t;
}
}
@rjeli
Copy link
Author

rjeli commented Jun 15, 2016

(defn counting-logger [every message-fn]
  (let [count (atom 0)]
    (fn [x] (when-not (mod x every) (println (message-fn x))) (swap! count inc) x)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment