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 buildo | |
import anorm._ | |
import shapeless._ | |
import shapeless.ops.hlist._ | |
import shapeless.record._ | |
import shapeless.syntax.std.traversable._ | |
import shapeless.syntax.singleton._ |
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 editResult(testId: LabOnlineId[Test], worklistId: LabOnlineId[Worklist], result: TestResult): Future[ActionResult] = | |
for { | |
test <- ensureExists(testId)(testData.findOne(_)) | |
sample <- ensureExists(test._sampleId)(sampleData.findOneWithWorklist(_, worklistId)) | |
} yield { | |
(ensureNotClosed(sample, worklistId) |@| | |
ensureNotClosed(test, worklistId))((_,_)) match { | |
case Failure(errors) => ActionResult.UserError(errors.toList: _*) | |
case Success(_) => /* run a stored procedure */ ActionResult.Ok | |
} |
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 gen(n: Int, limit: Int, k: Int = 1): Iterator[List[Int]] = { | |
val range = (k until limit).iterator | |
n match { | |
case _ if n > 0 => for { | |
x <- range | |
y <- gen(n - 2, limit, x) | |
} yield x :: y | |
case _ => range.map(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
package example | |
import scala.language.existentials | |
import shapeless._; import record._; import ops.record._; import ops.hlist._ | |
import spray.routing.SimpleRoutingApp | |
trait AutoGetParametersModule { self: SimpleRoutingApp => | |
import spray.routing.{ Directive, Directive1, Directive0, HListDeserializer } |
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
module Matrix | |
data Matrix : Nat -> Nat -> Type -> Type where | |
Matr : Vect m (Vect n a) -> Matrix n m a | |
(+) : Matrix n m a -> Vect n a -> Matrix n (m + 1) a | |
(+) (Matr rows) row = Matr (rows ++ [row]) | |
implicit vectVectToMatr : Vect m (Vect n a) -> Matrix n m a | |
vectVectToMatr = Matr |
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
let if = macro { | |
rule { | |
($x:expr) { | |
$truebody | |
... | |
$truelast:expr | |
} else { | |
$falsebody | |
... | |
$falselast:expr |
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 scalaz._; import Scalaz._ | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
def getInteger(x: Int): OptionT[Future, Int] = 42.point[Future].liftM[OptionT] | |
def computeList(n: Int): OptionT[Future, List[Int]] = (1 to n).toList.traverseU(getInteger) | |
//if you need a Future[OptionT[List[Int]]] just use run | |
computeList(3).run // Some(List(1, 2, 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
import scala.concurrent._ | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
def getInteger(x: Int) = Future.successful( | |
if (x == 11) None else Some(x)) | |
def sequence[T](l: Seq[Option[T]]): Option[List[T]] = l.foldRight(Some(Nil) : Option[List[T]]) { | |
(or, ox) => for (r <- or; x <- ox) yield (r :: x) | |
} |
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
object Messages { | |
type IString = I18nString[En with It] | |
val cart: IString = en"Shopping cart" | it"Carrello" | |
val login: IString = en"Login" | it"Accedi" | |
val betReplayedBy: IString = | |
en""" | |
Ticket replayed by {n, plural, |
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
API.cancelConsultation(consultation._id) | |
|> showHUDOnStart(status: "canceling consultation") | |
|> showHUDOnSuccessAndError | |
|> start() |
OlderNewer