Skip to content

Instantly share code, notes, and snippets.


Vlad Patryshev vpatryshev

View GitHub Profile
vpatryshev / ArrayListToFunctor
Last active Dec 14, 2015
an example how java.util.ArrayList can be turned into a functor and get a functor's map() method.
View ArrayListToFunctor
* This trait (typeclass) defines one operation for a parametrized type F
* the operation is known as fmap in Haskell, f1 in internal categories.
* For each pair of arbitrary types X, Y and an arbitrary function:X=>Y,
* it should provide a function F[X]=>F[Y].
* Providing means that the implementation depends on a specific type F
* E.g. given F = List, and a function f(n: Int): String = "{{" + n + "}}",
* we should have a function List[Int]=>List[String] that wraps elements in double braces.
vpatryshev / RE.scala
Created Sep 24, 2012
regexp from Beautiful Code, in tongues
View RE.scala
case class Ch(c: Char) { def ~=(x: Char) = c == '.' || c == x }
class RE(val regexp: String) {
def skip(n: Int) = RE(regexp.substring(n))
implicit def token(c: Char) = Ch(c)
def c0 = Ch(regexp(0))
def c1 = regexp(1)
def ~=(text: String): Boolean = {