This file contains hidden or 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
module Main where | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Monad.Trans.List | |
import System.Directory | |
getAllFilesIn :: FilePath -> IO [FilePath] | |
getAllFilesIn path = runListT $ getAllFilesIn' path | |
where |
This file contains hidden or 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 scalaz._ | |
import Scalaz._ | |
object Bubble { | |
def bubbleSort[A: Order](xs: List[A]) = xs.unfold[Stream, A] { | |
_.foldr[Option[(A, List[A])]](none){ (x, zs) => | |
zs.fold({case (y, ys) => (x lt y).fold((x, y::ys), (y, x::ys))}, (x, nil[A])).some | |
} | |
} | |
} |
This file contains hidden or 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 BinTreeIterator { | |
sealed trait Tree | |
case class Node(v: Int, l: Tree, r: Tree) extends Tree | |
case object Leaf extends Tree | |
def toIterator(node: Tree): Iterator[Int] = { | |
def toStream(n: Tree): Stream[Int] = n match { | |
case Node(v, l, r) => v #:: toStream(l) #::: toStream(r) | |
case Leaf => Stream.empty | |
} |
This file contains hidden or 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
def find2[A](x:A, xs:List[A]):Option[A] = { | |
if(xs.nonEmpty){ | |
if(xs.head == x) Some(xs.head) | |
else find2(x, xs.tail) | |
} else { | |
None | |
} | |
} | |
def find3[A](x:A, xs:List[A]):Option[A] = | |
xs.headOption match { |