This file contains hidden or 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
type ID = Long | |
type Code = String | |
class User(val id: ID, | |
val name: String, | |
val friends: List[User]) | |
class UserDto(val code: Code, | |
val name: String, | |
val friends: List[UserDto]) { |
This file contains hidden or 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
(ns rss-reader | |
(:import [java.io FileReader | |
BufferedReader]) | |
(:require [clojure.xml :as xml] | |
[clojure.zip :as zip]) | |
(:use [clojure.contrib.zip-filter.xml] | |
[hiccup.core])) | |
(defn print-feeds [feeds] | |
(doseq [[channel articles] feeds] |
This file contains hidden or 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 scala.collection.mutable.MultiMap | |
import java.net.URLEncoder | |
import scala.collection.mutable.{Set => MSet, HashMap, MultiMap} | |
class LinkBuilder(path: String) { | |
val attributes = new HashMap[String, MSet[String]] with MultiMap[String, String] | |
override def toString(): String | |
= path + | |
"?" + |
This file contains hidden or 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.string :only (join)]) | |
(import java.net.URLEncoder) | |
(defn link-builder [path] {:path path | |
:attributes {}}) | |
(defn add [lb k v] | |
(when v | |
(update-in lb [:attributes k] concat #{v}))) | |
This file contains hidden or 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
(defn index-of-any [coll pred] | |
(loop [index 0 | |
items coll] | |
(when (not (empty? items)) | |
(if (pred (first items)) | |
index | |
(recur (inc index) (rest items)))))) | |
(index-of-any "foobar" #{\c \d \b}) ; -> 3 |
This file contains hidden or 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
(defn- in-transaction [f] | |
(try | |
(do (println "starting...") | |
(let [rv (f)] | |
(println "commiting...") | |
rv)) | |
(catch Exception e | |
(println "rollbacking...")))) | |
(defmacro transactional [expr] |
This file contains hidden or 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
class C { def b = "b" } | |
trait T extends C { override def b = "trait b" } | |
val c = new C with T | |
c.b // => java.lang.String = trait b |
This file contains hidden or 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
;; Gathers values up to (and including) the one for | |
;; which the predicate fails. | |
(defn take-to | |
[pred coll] | |
(when-let [s (seq coll)] | |
(let [[x & xs] s] | |
(if-not (pred x) | |
(list x) | |
(lazy-cat (cons x (take-to pred xs))))))) |
This file contains hidden or 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 dictionary | |
(with-open [rdr (reader "/usr/share/dict/words")] | |
(conj (set (line-seq rdr)) "clojure"))) | |
(defn correctly-spelled? | |
[sentence] | |
(->> (.toLowerCase sentence) | |
(re-seq #"\w+") | |
(every? dictionary))) |
This file contains hidden or 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
(require 'clojure.set) | |
(def connections | |
["3-4" | |
"4-9" | |
"8-0" | |
"2-3" | |
"5-6" | |
"2-9" | |
"5-9" |