Skip to content

Instantly share code, notes, and snippets.

(let [channel (create)
incremented-values (map* inc channel)
decremented-values (map* dec channel)]
(consume incremented-values (fn [i] (println "Incremented value: " i)))
(consume decremented-values (fn [i] (println "Decremented value: " i)))
(accept channel 1)
(accept channel 2)
(accept channel 3)
(ms/flush channel))
package introspect;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.AllArguments;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.Origin;
import java.lang.reflect.Method;
public class LogInterceptor {
public static void log(@AllArguments Object[] allArguments,
@Origin Method method) {
import Control.Concurrent.ParallelIO.Global (parallel)
import Control.Arrow (left)
data DbError = DbError
data Input = Input
data Result = Result
someOperation :: Either DbError [Input]
-> (Input -> IO (Either DbError Result))
-> IO (Either DbError [Result])
@ifesdjeen
ifesdjeen / Haskell Simplification 1.hs
Last active February 11, 2018 13:05
I've got that piece of code that looks extremely overcomplicated to me. Even though every operation by itself is simple, the "sum" of operations is simply insane.
data Query = Query
data SomeObj = SomeObj
data IoOnlyObj = IoOnlyObj
data Err = Err
-- There's a decoder function that makes some object from String
decodeFn :: String -> Either Err SomeObj
decodeFn = undefined
-- There's a query, that runs against DB and returns array of strings

First of all, sorry for the messy code (it was in a bad condition, and I've been commenting/uncommenting bunch of things to understand what's going on and where, only got time to fix it but not clearnup)

At first, I've started getting

Stack space overflow: current size 8388608 bytes.
;; "Normal" operation order
(->> [1 2 3]
(map inc)
(map #(* 2 %)
(reduce +))
(defn almost=
"Non-strict equality"
[wat center tolerance]
(and (>= wat (- center tolerance))
(<= wat (+ center tolerance))))
@ifesdjeen
ifesdjeen / Haskell vs Clojure Tail Rec.clj
Last active August 29, 2015 13:56
Comparison of tailrec+pattern matching between Haskell and Clojure
(defn max-from-list
"Get the maximum from list using recursion"
[[head & tail]]
(if (empty? tail)
head
(let [max-in-tail (max-from-list tail)]
(if (> head max-in-tail)
head
max-in-tail))))
@ifesdjeen
ifesdjeen / deploy_jar.rb
Created October 17, 2013 12:33
If you're deploying 20 Clojure libs a day (and keep forgetting Clojars deploy syntax), you're going to love that script. Maybe there's a leiningen task for that, never tried.
#!/usr/bin/ruby
res = `lein do pom, jar`
jar = res.split("\n").last.gsub("Created ", "")
puts "Gonna deploy jar: #{jar}"
exec "scp pom.xml #{jar} clojars@clojars.org:"