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.util.UUID | |
object Test { | |
implicit def columnMap2Map[A, B](map: Map[Array[Byte], Array[Byte]]) = new MapConverter(map) | |
class MapConverter(map: Map[Array[Byte], Array[Byte]]) { | |
def to[A, B](implicit f: Array[Byte] => A, g: Array[Byte] => B): Map[A, B] = { | |
map.foldLeft(Map[A, B]()) { case(map, (k, v)) => | |
val tuple = (k: A, v: B) | |
map + tuple |
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 Bah { | |
def iterate[T](t: T)(f: T => Option[T]): Iterator[T] = new Iterator { | |
var next = Some(t) | |
override def hasNext = next.isDefined | |
override def next = { | |
val result = next.get | |
next = f(result) | |
result | |
} | |
} |
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
// in src/main/scala/foo/bar/BarTrait.scala | |
package foo.bar | |
trait BarTrait |
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
implicit def MapMonoid[K, V](implicit valueSemigroup: Semigroup[V]): Monoid[Map[K, V]] = new Monoid[Map[K, V]] { | |
override val zero = Map.empty[K, V] | |
override def append(m1: Map[K, V], m2: => Map[K, V]) = { | |
val (from, to, semigroup) = { | |
if (m1.size > m2.size) (m2, m1, (v1: V, v2: V) => valueSemigroup.append(v1, v2)) | |
else (m1, m2, (v1: V, v2: V) => valueSemigroup.append(v2, v1)) | |
} | |
from.foldLeft(to) { | |
case (to, (k, v)) => to + (k -> to.get(k).map(semigroup(_, v)).getOrElse(v)) |
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
implicit def MapMonoid[K, V](implicit valueSemigroup: Semigroup[V]): Monoid[Map[K, V]] = new Monoid[Map[K, V]] { | |
override val zero = Map.empty[K, V] | |
override def append(m1: Map[K, V], m2: => Map[K, V]) = { | |
val (from, to, semigroup) = { | |
if (m1.size > m2.size) (m2, m1, (v1: V, v2: V) => valueSemigroup.append(v1, v2)) | |
else (m1, m2, (v1: V, v2: V) => valueSemigroup.append(v2, v1)) | |
} | |
from.foldLeft(to) { | |
case (to, (k, v)) => to + (k -> to.get(k).map(semigroup(_, v)).getOrElse(v)) |
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
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] | |
def flatMap[A, B](f: A => M[B]): M[A] => M[B] | |
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a))) | |
} | |
class Reader[I] extends Monad[({type M[O] = Function1[I, O]})#M] { | |
def pure[A](a: A): Function1[I, A] = error("todo") | |
def flatMap[A, B](f: A => Function1[I, B]): Function1[I, A] => Function1[I, B] = error("todo") | |
} |
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
implicit def pf[A](a: A): PF[A] = new PF(a) | |
class PF[A](a: A) { | |
def option[B](pf: PartialFunction[A, B]): Option[B] = pf.lift.apply(a) | |
} |
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
(08:14:03 PM) nuttycom: dobblego: if you're about, there is something I'd like to learn from you. :) | |
(08:14:12 PM) dobblego: I have 15 minutes | |
(08:14:17 PM) nuttycom: I'd like to learn the meaning of "kleisli" | |
(08:14:27 PM) dobblego: it's the monad transformer for Function1 | |
(08:14:35 PM) dobblego: A => F[B] | |
(08:14:59 PM) dobblego: it gives some useful properties | |
(08:15:14 PM) dobblego: if F is a monad, then A => F[?] is a monad | |
(08:15:31 PM) copumpkin: another view is that every monad gives rise to a category | |
(08:15:42 PM) copumpkin: where you have identity and composition like you do with regular functions | |
(08:16:09 PM) copumpkin: except composition is (A => M[B], B => M[C]): A => M[C] |
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=/^.*case object[ \t]+([a-zA-Z0-9_]+)/\1/o,case objects/ | |
--regex-scala=/^.*object[ \t]+([a-zA-Z0-9_]+)/\1/o,objects/ | |
--regex-scala=/^.*case class[ \t]+([a-zA-Z0-9_]+)/\1/c,case classes/ | |
--regex-scala=/^.*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/ | |
--regex-scala=/^.*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/ | |
--regex-scala=/^.*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/ | |
--regex-scala=/^.*def[ \t]+([a-zA-Z0-9_\?]+)/\1/m,methods/ | |
--regex-scala=/^.*val[ \t]+([a-zA-Z0-9_]+)/\1/C,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
sealed trait A { | |
type X | |
case class B(x: X) | |
def b: B | |
} | |
case class J(x: String) extends A { | |
type X = String | |
override def b = B(x) |
OlderNewer