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
// | |
// Packages a value into a new, type-safe wrapper. The value can always be safely unwrapped. | |
// | |
public protocol NewType: CustomStringConvertible { | |
// The type of the wrapped value | |
typealias Unwrapped | |
// Accessor for the underlying value | |
var unwrapped: Unwrapped { get } |
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
rep : (n : Nat) -> a -> List a | |
rep Z x = [] | |
rep (S k) x = x :: rep k x | |
data RLE : List Char -> Type where | |
REnd : RLE [] | |
RChar : (n : Nat) -> (c : Char) -> (rs : RLE xs) -> RLE (rep n c ++ xs) | |
rle : (xs : List Char) -> RLE xs | |
rle [] = REnd |
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 -cp Thyme.jar | |
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> val th = new ichi.bench.Thyme | |
th: ichi.bench.Thyme = ichi.bench.Thyme@7464fb1c | |
scala> th.pbenchOff[Exception]("stacktraces")(new Exception("foo") with scala.util.control.NoStackTrace, ftitle = "without")(new Exception("foo"), htitle = "with") | |
Benchmark comparison (in 20.94 s): stacktraces |
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
def notNull[A](a: A): Validation[String, A] = | |
if (a != null) a.success else "may not be null".failure | |
def size[A <% Traversable[_]](min: Int = 0, max: Int = Int.MaxValue)(a: A): Validation[String, A] = | |
if (min to max contains a.size) a.success else s"size must be between $min and $max".failure | |
// Composing notNull and size, like https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/constraints/NotEmpty.java#L48 | |
def notEmpty[A <% Traversable[_]](a: A): Validation[String, A] = | |
notNull(a) flatMap size(min = 1) |
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
Benchmark comparison (in 9.612 s): delete 1 shuffled values | |
btree vs treeset | |
Significantly different (p ~= 0) | |
Time ratio: 0.76712 95% CI 0.73631 - 0.79793 (n=20) | |
btree 78.60 ns 95% CI 75.96 ns - 81.25 ns | |
treeset 60.30 ns 95% CI 58.98 ns - 61.62 ns | |
Benchmark comparison (in 13.16 s): delete 10 shuffled values | |
btree vs treeset | |
Significantly different (p ~= 7.567e-11) | |
Time ratio: 1.06081 95% CI 1.04667 - 1.07495 (n=20) |
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
name := "timeseries" | |
scalaVersion := "2.10.0" | |
libraryDependencies ++= Seq( | |
"joda-time" % "joda-time" % "2.1", | |
"org.joda" % "joda-convert" % "1.3") |
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
/** | |
* Publishes successful commits to subscribers. | |
*/ | |
trait CommitPublisher[Event] { | |
/** | |
* Notifies `listener` of all commits that happened `since`. Notification happens asynchronously. | |
*/ | |
def subscribe(since: StoreRevision)(listener: Commit[Event] => Unit): Subscription | |
} |
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
/** | |
* A specific blog post with its current content. | |
*/ | |
case class Post(id: PostId, content: PostContent) | |
/** | |
* The current state of blog posts, derived from all committed PostEvents. | |
*/ | |
case class Posts(byId: Map[PostId, Post] = Map.empty, orderedByTimeAdded: Seq[PostId] = Vector.empty) { | |
def get(id: PostId): Option[Post] = byId.get(id) |
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
package lenses | |
import com.codahale.jerkson._, AST._ | |
/** | |
* Lenses allow retrieving and updating values of type `B` inside some enclosing value of type `A`. | |
* | |
* Since lenses can be composed together, arbitrary nesting is automatically taken care of. | |
*/ | |
case class Lens[A, B](get: A => B, set: (A, B) => A) { |
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
# --- !Ups | |
create table users ( | |
name text primary key, | |
age int not null); | |
# --- !Downs | |
drop table users; |
NewerOlder