Skip to content

Instantly share code, notes, and snippets.

import sys.process._
val com = inputKey[Unit]("Run an external command")
import complete.DefaultParsers._
com := {
val args: Seq[String] = spaceDelimited("external command. eg. ls -l .").parsed
val command = Seq("sh", "-c", s"${args.mkString(" ")}")
val pl = ProcessLogger(println(_), e => println(s"""\033[31m$e"""))
//put in ~/.sbt/1.0/global.sbt if you want this to be the default shell everywhere
import scala.sys.process._
import scala.util.Try
shellPrompt := { s: State =>
val extracted = Project.extract(s)
val devNull = ProcessLogger(_ => ())
package com.example.circe
import io.circe._
import io.circe.parser._
object HelloWorld {
val deprecatedKeys = Vector("foo")
def main(args: Array[String]) {

Hello everyone! My name is Sanjiv. Welcome to our presentation on using Types for Quality. There will be four presentations followed by some time for questions and answers at the end. First off, we have Luke, who will talk to us about some common problems faced when developing software. Over to you Luke.

Putting the Algebra in Data Types

  • What is an Algebra in Mathematics?

    • Symbols (0,1,2,3,x,y,z ...)
    • Operations (+, -,*, / ...)
    • Laws (associativity, commutativity, identity ...)

    a + b = b + a

  • How does it relate to Computing?

//Throwable
// - Error //never catch
// - Exception //"checked" in Java
// - RuntimeException // "unchecked in Java
class NotAnIntException(message: String) extends Exception(message)
def strToInt(value: String): Int =
if (value.forall(_.isDigit)) value.toInt
//definition of Either
sealed trait Either[+A, +B]
case class Left[A](a: A) extends Either[A, Nothing]
case class Right[B](b: B) extends Either[Nothing, B]
//whiteboard
//Right -> Results
//Left -> Errors
@ssanj
ssanj / IntroExercises.scala
Last active April 29, 2018 11:25
intro-to-scala course notes
//Currying is the process of transforming a function that takes multiple arguments into a
//function that takes just a single argument and returns another function if any arguments are still needed.
def curriedAdd2: Int => Int => Int = x => y => x + y
:t curriedAdd2
//Int => (Int => Int)
curriedAdd2(5)
@ssanj
ssanj / ReaderT_and_WriterT.hs
Created January 8, 2018 00:54 — forked from Decoherence/ReaderT_and_WriterT.hs
Haskell: Monad Transformers -- Combine ReaderT and WriterT
-- | Main entry point to the application.
module Main where
import Control.Monad.Reader
import Control.Monad.Writer
{-
The ReaderT transformer is used to retrieve a read-only value from some environment.
The WriterT transformer will log the result of each retrieval.
Running the two transformers together yields a log of each step along with the actual results.
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Sample(perform, runAsIO, runAsSt) where
import Text.Printf (printf)
import qualified Control.Monad.Trans.State as S
class Monad m => ConsoleR m where
writeLine :: String -> m ()