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 Control.Monad.Identity | |
import Control.Monad.Error | |
type Scott = ErrorT String Identity Int | |
myf :: Int -> Scott | |
myf i = return i | |
lar :: Scott | |
lar = do |
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 Data.List | |
mylst = [(1,3), (2,4), (5,6), (5,7), (6,8)] | |
findOverlaps :: [(Int,Int)] -> [(Int,Int)] | |
findOverlaps xs = | |
let sorted = sortBy (\x y -> if ((fst x) < (fst y)) then LT else GT) xs | |
foldF acum elem = | |
let (doneLst, (blockMin,blockMax)) = acum | |
(elemMin, elemMax) = elem |
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=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\4/c,case classes/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/ | |
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\3/m,methods/ | |
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*val[ \t]+([a-zA-Z0-9_]+)/\3/l,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
// I ran into this gotcha while working with scalaz.EitherT. | |
// I was trying to do a flatMap that changed the left of an EitherT from one type to another. | |
// In the below type definition the left is the 'A' type. | |
// EitherT[F[_], A, B] | |
// flatMap[C](f: B => EitherT[F, A, C])(implicit F: Monad[F]): EitherT[F, A, C] | |
import scalaz._ | |
import scala.concurrent.Future |
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.sql._ | |
import scala.util.Try | |
object DbEnv { | |
trait Closeable { | |
def close: Unit | |
} |
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
// EitherT moved from being covariant in scalaz 7.0 to being invariant in scalaz 7.1 | |
// I heavily used sealed traits for ADTs. This solves the problem, I just need to write a whole lot more bullshit. | |
sealed trait Person { | |
val name: String | |
val job: String | |
} | |
trait Plumber extends Person | |
object Plumber { |
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 scala.util.{Try, Success, Failure} | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits._ | |
object FutureTests { | |
/* | |
* Success callback example. | |
*/ | |
def test1 { |
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
// Case classes | |
// Algebraic Data Types | |
// Objects | |
// Currying | |
// Traits | |
// Classes | |
// The Cake | |
// CASE CLASSES |
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 ground | |
// Show that println and Unit are not the same. | |
// Why pure IO? | |
// Trampoline | |
// IO values and interpreters | |
object UnitIsNotUnit { | |
// Side effects are extremely hard to reason about. |
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 ground | |
// Why pure IO? | |
// Trampoline | |
// IO values and interpreters | |
object UnitIsNotUnit { | |
// Side effects are extremely hard to reason about. | |
// The only way you can tell when they are executed is by following imperative code |