View gist:5491536
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
22:06 ~/Projects/Kepler_5923/sandbox (ticket/5923)$ cat Macros.scala | |
import language.experimental.macros | |
import scala.reflect.macros.Context | |
trait Iso[T, U] { | |
def to(t : T) : U | |
// def from(u : U) : T | |
} | |
object Iso { |
View gist:5537188
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
// Usage examples: | |
val a = Vector(1,2,3).zipMany(Vector(1,2,3), Vector(5,6,7), Vector(8,9,10), Vector(11,12,13)) | |
Vector(Vector(1, 1, 5, 8, 11), Vector(2, 2, 6, 9, 12), Vector(3, 3, 7, 10, 13)) | |
a.unzipMany | |
Vector(Vector(1, 2, 3), Vector(1, 2, 3), Vector(5, 6, 7), Vector(8, 9, 10), Vector(11, 12, 13)) | |
// Implementation | |
import scala.collection._ | |
import scala.collection.generic.CanBuildFrom |
View JValueWithFilter.scala
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 org.json4s.JValue | |
implicit class LiftJValueWithFilter(self: JValue) | |
extends JValueWithFilter(self, _ => true) | |
class JValueWithFilter(self: JValue, p: JValue => Boolean) { | |
def map(f: JValue => T): List[T] = | |
self.filter(p).map(f) | |
def flatMap(f: JValue => List[T]): List[T] = | |
self.filter(p).flatMap(f) | |
def foreach(f: JValue => Unit): Unit = |
View ::.scala
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
final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B] | |
override def head: B = hd | |
override def tail: List[B] = tl | |
override def isEmpty: Boolean = false | |
private def readObject(in: ObjectInputStream): Unit = | |
val firstObject = in.readObject() | |
hd = firstObject.asInstanceOf[B] | |
assert(hd != ListSerializeEnd) | |
var current: ::[B] = this |
View CCC.scala
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
// Scala Types are objects of Cartesian Closed Category | |
// (w/o equalities, probably not a category, sorry) | |
object CCC { | |
// category structure | |
def id[T0]: T0=>T0 = x0=>x0 | |
def mul[T1, T2, T3](f23: T2=>T3, f12: T1=>T2): (T1=>T3) = x1 => f23(f12(x1)) | |
// terminal object; adjunction; | |
type _1_ = Unit |
View package.scala
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 object types { | |
import scala.language.reflectiveCalls | |
import scala.language.higherKinds | |
// quantifiers aka (co)ends | |
type Forall[+F[_]] = { def apply[X]: F[X] } | |
type Exists[+F[_]] = F[_] | |
// basic categorical notions |
View CAT.scala
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 cat | |
object CAT { | |
// system traits | |
sealed trait Type[Self <: Type[Self]] | |
sealed trait Of[Self <: Of[Self, T], T <: Type[T]] | |
// types | |
case class Ob() |
View LinVect.scala
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 LinVect { | |
type K = Double | |
trait NAT[N] { val nat: Int } | |
def NAT[N: NAT]: NAT[N] = implicitly | |
def nat[N: NAT]: Int = NAT[N].nat | |
trait NAT_10 | |
implicit object NAT_10 extends NAT[NAT_10] |
View config.scala
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 scalaz.example | |
object Reader extends App { | |
/** | |
* Manual propagation of the environment (in the example, `contextRoot`.) | |
*/ | |
object Config0 { | |
def fragment1(contextRoot: String) = <a href={contextRoot + "/foo"}>foo</a> |
View HexBytesUtil.scala
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 HexBytesUtil { | |
def hex2bytes(hex: String): Array[Byte] = { | |
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2, 2).toArray.map(Integer.parseInt(_, 16).toByte) | |
} | |
def bytes2hex(bytes: Array[Byte], sep: Option[String] = None): String = { | |
sep match { | |
case None => bytes.map("%02x".format(_)).mkString | |
case _ => bytes.map("%02x".format(_)).mkString(sep.get) |
OlderNewer