Skip to content

Instantly share code, notes, and snippets.

@psttf
psttf / ConstZipper.scala
Created November 25, 2013 11:50
ConstZipper zips an HList with a constant value
import shapeless._
object cz {
trait ConstZipper[L <: HList, C] extends DepFn2[L, C] { type Out <: HList }
object ConstZipper {
type Aux[L <: HList, C, Out0 <: HList] =
ConstZipper[L, C] { type Out = Out0 }
@psttf
psttf / MatchTypes.scala
Last active December 28, 2015 18:29
Find values of the same types in HList
import shapeless._
import poly._
import shapeless.ops.hlist.FlatMapper
object am {
/**
* A type class that helps us partially apply a polymorphic binary function
* to some value and map the resulting function (which of course isn't
* literally a Poly1) over an HList.
@psttf
psttf / concatenate
Last active December 20, 2015 06:39
Concatenates all files in current directory and subdirectories, inserting filename before each new file. Set to process only .scala files by default.
import java.io.File
import scala.io._
import scala.util.matching.Regex
def recursiveListFiles(f: File, r: Regex): Array[File] = {
val these = f.listFiles
val good = these.filter(f => r.findFirstIn(f.getName).isDefined)
good ++ these.filter(_.isDirectory).flatMap(recursiveListFiles(_,r))
}