(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.
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html and the generic version https://gist.github.com/2571928 | |
class YFact { | |
// T function returning a T | |
// T -> T | |
public static interface Func<T> { | |
T apply(T n); | |
} | |
// Higher-order function returning a T function |
(ns powerset.core-test | |
(:use (clojure set test))) | |
(defn powerset [s] | |
(apply union | |
#{s} ;the complete set of all s | |
(map (fn [i] (powerset (disj s i))) s))) | |
(deftest test-powerset | |
(is (= #{#{}} |
box: wercker/default | |
services: | |
- wercker/postgresql | |
- wercker/rabbitmq | |
- wercker/redis | |
build: | |
steps: | |
- script: | |
name: install clojure | |
code: | |
def knapsack_aux(x: (Int, Int), is: List[Int]): List[Int] = { | |
for { | |
w <- is.zip(is.take(x._1) ::: is.take(is.size - x._1).map(_ + x._2)) | |
} yield math.max(w._1, w._2) | |
} | |
def knapsack_rec(xs: List[(Int, Int)], is: List[Int]): List[List[Int]] = { | |
xs match { | |
case x :: xs => knapsack_aux(x, is) :: knapsack_rec(xs, knapsack_aux(x, is)) | |
case _ => Nil |
(use 'clojure.core.async) | |
(defprotocol ISendable | |
(channel [this])) | |
(defn async-agent [state] | |
(let [c (chan Long/MAX_VALUE) ;; <<-- unbounded buffers are bad, but this matches agents | |
a (atom state)] | |
(go-loop [] | |
(when-let [[f args] (<! c)] |
package java8tests ; | |
import java.util.function.BiFunction ; | |
import java.util.function.Function ; | |
public class Currying { | |
public void currying() { | |
// Create a function that adds 2 integers | |
BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ; |
package pipe_foundations.example; | |
import pipe_foundations.Pipe; | |
import pipe_foundations.SimpleFilter; | |
public class ExampleFilter extends SimpleFilter<Integer, String> { | |
public ExampleFilter(Pipe<Integer> input, Pipe<String> output) { | |
super(input, output); | |
} |
(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.
If you don't have homebrew installed - get homebrew here
Then run: brew install elasticsearch
Update the elasticsearch configuration file in /usr/local/etc/elasticsearch/elasticsearch.yml
.
(ns clj-spec-playground | |
(:require [clojure.string :as str] | |
[clojure.spec :as s] | |
[clojure.test.check.generators :as gen])) | |
;;; examples of clojure.spec being used like a gradual/dependently typed system. | |
(defn make-user | |
"Create a map of inputs after splitting name." | |
([name email] |