Skip to content

Instantly share code, notes, and snippets.

abstract class Cloneable[T <: Cloneable[T]] {
def clone(original: T): T
}
class TestChild(name: String) extends Cloneable[TestChild] {
def clone(original: TestChild) = {
new TestChild(original.name)
}
}
abstract class AbsIterator {
type T
def hasNext: Boolean
def next: T
}
trait RichIterator extends AbsIterator {
def foreach(f: T => Unit) { while (hasNext) f(next) }
}
trait Logger {
def log(msg: String)(implicit logType: String) = {
println(s"${logType}: ${msg}")
}
}
object DefaultLogger extends Logger
class SomeClass {
implicit val logType = "SomeClass"
trait BobLike {
val name = "Bob"
}
trait PersonLike {
var money: Double
def isWealthy = money > 10000000
}
extension Array {
mutating func appendReturn(item: Array.Element)-> Array.Element {
self.append(item)
return item
}
}
import Foundation
enum Coin: Int, CustomStringConvertible {
case Tails, Heads
var description: String {
if self == .Tails {
return "T"
} else {
return "H"
object Main extends App {
implicit val queue: dispatch.queue = "goodbyeQueue"
def sayHello = () => {println("hello")}
def sayGoodbye = () => {println("goodbye")}
dispatch.async(sayHello)("helloQueue")
dispatch async sayGoodbye
}
enum Testing: String {
case Thing = "thing"
case Bob = {.Bob + "hello"}
}
class Test {
struct Inside {
}
}
let a = [Test.Inside]()
struct Bob {
let lastName: String
static var creth: Bob {
return Bob(lastName: "Creth")
}
static func bobNamedFlumper() -> Bob {
return Bob(lastName: "Flumper")
}