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 com.knollop.wharton.store.mongo | |
import play.api.libs.json._ | |
import com.mongodb._ | |
import com.knollop.wharton.store._ | |
import org.bson.types.ObjectId | |
trait MCollection extends DBObjectTransformer { | |
def mongoDb: DB | |
val collectionName: String |
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
val filename = "conf/my_file.txt" | |
val lines = scala.io.Source.fromFile(filename).getLines.toList | |
var linePtr = 0 | |
def sendLine { | |
if(linePtr == lines.length) { | |
clock.cancel() | |
} | |
else { | |
testStream ! Message(lines(linePtr)) |
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 Control.Monad.Identity | |
import Control.Monad.Error | |
type Scott = ErrorT String Identity Int | |
myf :: Int -> Scott | |
myf i = return i | |
lar :: Scott | |
lar = do |
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 Data.List | |
mylst = [(1,3), (2,4), (5,6), (5,7), (6,8)] | |
findOverlaps :: [(Int,Int)] -> [(Int,Int)] | |
findOverlaps xs = | |
let sorted = sortBy (\x y -> if ((fst x) < (fst y)) then LT else GT) xs | |
foldF acum elem = | |
let (doneLst, (blockMin,blockMax)) = acum | |
(elemMin, elemMax) = elem |
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
--langdef=scala | |
--langmap=scala:.scala | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\4/c,case classes/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/ | |
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\3/m,methods/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*val[ \t]+([a-zA-Z0-9_]+)/\3/l,constants/ |
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
// I ran into this gotcha while working with scalaz.EitherT. | |
// I was trying to do a flatMap that changed the left of an EitherT from one type to another. | |
// In the below type definition the left is the 'A' type. | |
// EitherT[F[_], A, B] | |
// flatMap[C](f: B => EitherT[F, A, C])(implicit F: Monad[F]): EitherT[F, A, C] | |
import scalaz._ | |
import scala.concurrent.Future |
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 java.sql._ | |
import scala.util.Try | |
object DbEnv { | |
trait Closeable { | |
def close: Unit | |
} |
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
// EitherT moved from being covariant in scalaz 7.0 to being invariant in scalaz 7.1 | |
// I heavily used sealed traits for ADTs. This solves the problem, I just need to write a whole lot more bullshit. | |
sealed trait Person { | |
val name: String | |
val job: String | |
} | |
trait Plumber extends Person | |
object Plumber { |
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 scala.util.{Try, Success, Failure} | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits._ | |
object FutureTests { | |
/* | |
* Success callback example. | |
*/ | |
def test1 { |
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
// Case classes | |
// Algebraic Data Types | |
// Objects | |
// Currying | |
// Traits | |
// Classes | |
// The Cake | |
// CASE CLASSES |
OlderNewer