This file contains 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 org.specs2.mutable._ | |
import org.specs2.specification._ | |
import org.specs2.matcher._ | |
import org.specs2.execute._ | |
import org.specs2.control.Debug | |
import org.specs2.main.ArgumentsShortcuts | |
import akka.testkit.TestKitBase | |
import akka.actor.ActorSystem |
This file contains 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 MyActor extends TypedMessageActor { | |
import MyActor._ | |
def receive = ReceiveMessage[AllowedMessage] { | |
case Message1(text) => | |
... | |
case Message2 => | |
... | |
} | |
This file contains 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
// Scala - you gotta love it. | |
class MPSList[T](val list: List[T]) { | |
def removeByIndex(index: Int): MPSList[T] = { | |
new MPSList[T](list.remove(list.indexOf(_) == index)) | |
} | |
} | |
object MPSList { | |
implicit def mpsListToScalaList[T](list: List[T]) = new MPSList[T](list) |
This file contains 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
; It's a thing of beauty how easy it is to parse therapy intervals in Clojure. | |
; Therapy intervals are usually Strings like 1-0-3-0 or 1-0.5-1 to describe how many pills a patient is taking every day | |
(defn interval-value [interval] "Parses an interval String and returns its numerical value" | |
(reduce + (map #(Double/valueOf %) (re-seq #"[0-9]+(?:[\\.][0-9]+)?" interval)))) |
This file contains 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
// "Write less, do more" episode 1203: iterating Strings creates chars, yielding chars creates a String | |
def abbreviatedName(fullName: String) = for (ch <- fullName; if ch.isUpper) yield ch |
This file contains 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
// Best of both worlds - WebObjects + Scala | |
// valueForKeyPath operators | |
def parameters: NSArray[Parameter] = ... | |
def maxSortOrder = parameters.valueForKeyPath("sortOrder.@max").asInstanceOf[Int] | |
// Clone attributes of an EnterpriseObject (aka DB row with all non-relationship columns) | |
trait Cloning extends EOEnterpriseObject { | |
type EOType <: EOEnterpriseObject |
This file contains 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
;; marius' solution to Compress a Sequence | |
;; https://4clojure.com/problem/30 | |
#(map last (partition-by str %)) |
This file contains 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
;; msoutier's solution to Drop Every Nth Item | |
;; https://4clojure.com/problem/41 | |
(fn [coll n] | |
(keep-indexed #(if (not= 0 (mod (inc %1) n)) %2 nil) coll)) |
This file contains 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
;; msoutier's solution to Duplicate a Sequence | |
;; https://4clojure.com/problem/32 | |
#(interleave % %) |
This file contains 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
;; msoutier's solution to Pack a Sequence | |
;; https://4clojure.com/problem/31 | |
partition-by identity |
OlderNewer