Skip to content

Instantly share code, notes, and snippets.

View jedws's full-sized avatar

Jed Wesley-Smith jedws

View GitHub Profile
@jedws
jedws / console.scala
Created October 22, 2013 06:37
something very odd going on with scalaz-stream
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._, Scalaz._, stream._
import scalaz._
import Scalaz._
import stream._
scala> val chan = io.fileChunkR("build.sbt").mapOut { s => new String(s) }
@jedws
jedws / veryOdd.scala
Last active December 23, 2015 19:09
@hg_ just showed me this, pretty odd: can't create a subInstance Root as a val, but can as an object
import scalaz._, Scalaz._
trait Root {
type FT[A[+_], +B]
val FT: MonadTrans[FT]
def value: FT[Id, Unit]
}
trait Child extends Root { child =>
// error: an't existentially abstract over parameterized type A
@jedws
jedws / Times.scala
Last active December 21, 2015 04:09
import scalaz.{ Free, Functor, Monad, Scalaz, \/, syntax }
import Free._
import Scalaz.Id
import syntax.id._
import syntax.monad._
package times {
case class Times[+A](times: Vector[(Long, String)], a: A)
object Times {
@jedws
jedws / box.scala
Created August 15, 2013 07:15
template for implementing Monads that are executed using Free so they don't StackOverflowError
package koto
import scalaz.{Comonad, Equal, Free, Functor, Scalaz }
import scalaz.syntax.equal._
import scalaz.syntax.monad._
object box extends Interpreted {
trait Box[+A] extends HasFree[A] {
def get: A = free.go { _.a }
}
import scalaz.Monad
import scalaz.syntax.monad._
/**
* Non stack-using Foldable substitute
*/
trait Folder[F[_], A] {
def foldLefterM[G[_], B](z: B)(f: (B, A) => G[B])(implicit M: Monad[G]): G[B]
}
@jedws
jedws / Optional.java
Last active December 19, 2015 17:48
Optional.flatMap must declare the output type of the supplied function to be covariant
package com.atlassian.variance.test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Test;
import com.google.common.base.Function;
final class Optional<A> {
private final A a;
@jedws
jedws / gist:5914678
Last active December 19, 2015 06:49
Parameterized type tags
import scalaz._
import Scalaz._
import java.lang.{Long => JLong}
object ParameterizedTags {
trait Nanoseconds[A]
type SampleDuration[A] = JLong @@ Nanoseconds[A]
case class Bar(a: BarDuration)
@jedws
jedws / tuples.scala
Last active December 14, 2015 15:09
generic type-class composition for ProductN
object Tuples {
type AsMap[A] = A => Map[String, String]
case class Dooby(a: String)
case class Foo(b: String)
implicit val DoobyMapper =
(ev: Dooby) => Map("a" -> ev.a)
trait Higher[F[_]]
trait Box[A]
object Box {
implicit def HigherBox = new Higher[Box] {}
}
object Foo {
val box = implicitly[Higher[Box]] // compiles fine !!!
package com.fayi.ftp
object CSVParser {
val ADDRESS = "ftp://mirrors.kernel.org/gnu/README.DESCRIPTIONS"
val ADDRESS2 = "ftp://ftp.gnu.org/README"
def main(args: Array[String]) {
def parse(s: Stream[String]) = {
val cells = (_: String).split(",")