This file contains hidden or 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._ | |
/** | |
* A simple example of how applicative functors can shorten code | |
* adapted from chapter 8? of Real World Haskell | |
*/ | |
object OptionGolf { |
This file contains hidden or 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> def apply[A, B](a: A)(f: A => B) = f(a) | |
apply: [A,B](a: A)(f: (A) => B)B | |
scala> apply(1)(_ * 2) | |
res0: Int = 2 | |
scala> def apply[A, B](a: A, f: A => B) = f(a) | |
apply: [A,B](a: A,f: (A) => B)B | |
scala> apply(1, _ * 2) |
This file contains hidden or 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
# sh function to murder all running processes matching a pattern | |
# thanks 3n: http://twitter.com/3n/status/19113206105 | |
murder () { | |
ps | grep $1 | grep -v grep | awk '{print $1}' | xargs kill -9 | |
} |
This file contains hidden or 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
#!/bin/sh -e | |
# | |
# Usage: browser | |
# pipe html to a browser | |
# e.g. | |
# $ echo "<h1>hi mom!</h1>" | browser | |
# $ ron -5 man/rip.5.ron | browser | |
if [ -t 0 ]; then | |
if [ -n "$1" ]; then |
This file contains hidden or 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
// 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) |
This file contains hidden or 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> val l = List(1,2,3) | |
l: List[Int] = List(1, 2, 3) | |
// pattern matching | |
scala> l match { | |
| case s if s.forall(even(_)) => Some(l) | |
| case _ => None | |
| } | |
res37: Option[List[Int]] = None |
This file contains hidden or 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._ | |
/** | |
* playing with some of the ideas from the Haskell fclabels library | |
* using the new Lens functionality in scalaz | |
* | |
* http://hackage.haskell.org/package/fclabels | |
*/ | |
object LensTest { |
This file contains hidden or 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 test | |
import scalaz._ | |
import Scalaz._ | |
import test.IRange.Increment | |
sealed trait Limit[+Z] { | |
def open : Boolean | |
def bound : Option[Z] | |
final def closed = !open |
This file contains hidden or 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
//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 => "" |
OlderNewer