Skip to content

Instantly share code, notes, and snippets.

View fedesilva's full-sized avatar
👁️‍🗨️

federico silva fedesilva

👁️‍🗨️
View GitHub Profile
@retronym
retronym / type-bounds.scala
Created December 16, 2009 11:17
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
// for comprehension
scala> for {
| l <- List(2,5,10)
| m <- List(8,10,11)
| } yield l * m
res17: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)
// map a pure function into applicatives
scala> List(8,10,11) <*> (List(2,5,10) map (((_: Int) * (_: Int)).curried))
res18: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)
//Usage:
//override def pomPostProcess(node: Node): Node = mcPom(moduleConfigurations)(super.pomPostProcess(node))
trait McPom { self: DefaultProject =>
import scala.xml._
def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = {
//make sure we have a trailing slash so we deduplicate URLs properly
def cleanUrl(url: String) = url match {
case null => ""
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@dcsobral
dcsobral / WordCount.scala
Created November 25, 2011 13:00
WordCount
// Based on Fantom's word count example here: http://blog.joda.org/2011/11/guide-to-evaluating-fantom.html
// I'm commenting the lines that need changing, and leaving a few of them uncommented,
// as they are the same
// class WordCount {
object WordCount {
// Void main(Str[] args) {
def main(args: Array[String]) {
if (args.size != 1) {
@fedesilva
fedesilva / service
Created December 19, 2011 21:39 — forked from brentkirby/service
Unicorn + Runit + RVM
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {
@gclaramunt
gclaramunt / ListZipper.scala
Created January 18, 2012 02:46
Simple list zipper
case class ListZipper[T](rev:List[T], fwd:List[T]){
override def toString = rev.reverse.toString ++" " ++ fwd.toString
def read:T= fwd.head
def add(c:T)=ListZipper(rev,c::fwd)
def update(c:T)=ListZipper(rev,c::fwd.tail)
def remove()=ListZipper(rev,fwd.tail)
def back=ListZipper(rev.tail,rev.head::fwd)
def forward=ListZipper(fwd.head::rev,fwd.tail)
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog
@fedesilva
fedesilva / build.scala
Created March 12, 2012 22:04
sbt 0.11.2 task dependencies [PARTIALLY SOLVED]
import sbt._
import Keys._
/**
* How in the world do I make bye depend on hello?
* And how do I depend on a task like test?
* I have not been able to make this work
goodbyeTask <<= goodbyeTask.dependsOn(helloTask) as in https://github.com/harrah/xsbt/wiki/Tasks
no matter where I stick it!
Halp!
*/
@gclaramunt
gclaramunt / planes.scala
Created June 6, 2012 18:08
Very simple phantom types example
trait FlightStatus
trait Flying extends FlightStatus
trait Landed extends FlightStatus
case class Plane[Status <: FlightStatus]()
def land(p:Plane[Flying])=Plane[Landed]()
def takeOff(p:Plane[Landed])= Plane[Flying]()
val plane = new Plane[Landed]()