Skip to content

Instantly share code, notes, and snippets.

(ns test.dialect
(:require [clojure.contrib.string :as st]))
(defn pig-latinize [word]
(let [fs (str (first word))]
(str
(if (re-seq #"(?i)[aeiou]" fs)
word
(str (subs word 1) fs))
"ay")))
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
case class ElectricCar(b: Battery) { def batteryLevel = b.filledPercentage }
case class GasolineCar(g: GasTank) { def gasLevel = g.filledPercentage }
case class Battery(filledPercentage: Int) { def fill: Battery = Battery(100) }
case class GasTank(filledPercentage: Int) { def fill: GasTank = GasTank(100) }
trait Fills[C] {
def fill(car: C): C
@rsuniev
rsuniev / zipper.hs
Created April 14, 2011 10:53
JSON Zipper
module Zipper where
import Data.List
import Text.JSON
import Data.Maybe
import Control.Monad
data JSZipper = JSZipper {
parent :: Maybe JSZipper,
lefts :: [JSValue],
@rsuniev
rsuniev / spde.scala
Created May 19, 2011 15:41
SPDE example
smooth()
noStroke()
fill(226)
frameRate(10)
size(400,400)
case class Color(red:Int,blue:Int,green:Int)
case class Ball(x:Int,y:Int,color:Color,radius:Int)
def draw {
@rsuniev
rsuniev / Head.scala
Created June 3, 2011 18:39 — forked from purefn/Head.scala
print the first 10 chunks of input
import scalaz.{Failure => _, _}
import Scalaz._
import effects._
import iteratees._
import java.io._
object Head {
def main(args: Array[String]) {
val enum = enumStream[Seq[Byte], IO]((1 to 50).toStream.map(i => ("line " + i + "\n").getBytes.toSeq))
@rsuniev
rsuniev / gist:1010938
Created June 6, 2011 19:46 — forked from markhibberd/gist:1009072
Alt D List Example
package scalaz.example
import scalaz.AltDList._
object ExampleAltDList {
def main(args: Array[String]) = run
import scalaz._, Scalaz._
import IterV._
@rsuniev
rsuniev / MapImplicits.scala
Created June 8, 2011 21:48 — forked from nuttycom/MapImplicits.scala
Map implicits for scalaz
implicit def MapMonoid[K, V](implicit valueSemigroup: Semigroup[V]): Monoid[Map[K, V]] = new Monoid[Map[K, V]] {
override val zero = Map.empty[K, V]
override def append(m1: Map[K, V], m2: => Map[K, V]) = {
val (from, to, semigroup) = {
if (m1.size > m2.size) (m2, m1, (v1: V, v2: V) => valueSemigroup.append(v1, v2))
else (m1, m2, (v1: V, v2: V) => valueSemigroup.append(v2, v1))
}
from.foldLeft(to) {
case (to, (k, v)) => to + (k -> to.get(k).map(semigroup(_, v)).getOrElse(v))
@rsuniev
rsuniev / Head.scala
Created July 13, 2011 15:26 — forked from purefn/Head.scala
print the first 10 chunks of input
import scalaz.{Failure => _, _}
import Scalaz._
import effects._
import iteratees._
import java.io._
object Head {
def main(args: Array[String]) {
val enum = enumStream[Seq[Byte], IO]((1 to 50).toStream.map(i => ("line " + i + "\n").getBytes.toSeq))
@rsuniev
rsuniev / accounts.clj
Created July 13, 2011 16:18 — forked from stuartsierra/accounts.clj
Accounts concurrency example in Clojure
;; An example of the "accounts" program for Venkat Subramaniam's
;; Programming Concurrency Workshop, part 1
;;
;; Original Java code by Venkat Subramaniam (@venkat_s)
;; available at http://www.agiledeveloper.com/downloads.html
;; under "Workshop: Programming Concurrency"
;;
;; This code example by Stuart Sierra (@stuartsierra)
;;
;; Überconf 2011, Denver, Colorado