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
type FruitSalad = { | |
Apple: AppleVariety | |
Banana: BananaVariety | |
Cherries: CherryVariety | |
} |
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
-- Solution to https://adventofcode.com/2019/day/1 by @philip_schwarz | |
-- Based on following solution by @runarorama: | |
-- https://gist.github.com/runarorama/21e6876bd62812b9d61a312c75ec87a3 | |
use .base | |
use .base.test.internals.v1.Test forAll | |
use .base.Test | |
-- Part 1 |
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
fizzbuzz :: [String] | |
fizzbuzz = | |
let fizzes = cycle ["", "", "fizz"] | |
buzzes = cycle ["", "", "", "", "buzz"] | |
pattern = zipWith (++) fizzes buzzes | |
in zipWith combine pattern [1..] where | |
combine word number = | |
if null word then show number else word |
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 scalaz.std.vector.vectorMonoid | |
import scalaz.syntax.foldable.ToFoldableOps | |
import scalaz.syntax.semigroup._ | |
import scalaz.std.list.listInstance | |
// Vector append and prepend functions | |
assert( Vector(1,2) :+ 3 == Vector(1,2,3) ) | |
assert( 1 +: Vector(2,3) == Vector(1,2,3) ) |
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.util.{Date, Calendar} | |
import util.{Try, Success, Failure} | |
type Amount = BigDecimal | |
def today = Calendar.getInstance.getTime | |
case class Balance(amount: Amount = 0) | |
sealed trait Account { |
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.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration._ | |
import scala.io.StdIn.readLine | |
object Main { | |
trait Terminal[C[_]] { | |
def read: C[String] | |
def write(t: String): C[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
import scalaz._ | |
import Scalaz._ | |
import simulacrum._ | |
import stalactite._ | |
import scala.concurrent.Future | |
import scala.io.StdIn.readLine | |
object Main { | |
trait Terminal[C[_]] { |
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 scalaz._ | |
import Scalaz._ | |
import simulacrum._ | |
import stalactite._ | |
import scala.concurrent.Future | |
import scala.io.StdIn.readLine | |
object Main { | |
trait Terminal[C[_]] { |
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 scalaz._ | |
import Scalaz._ | |
import simulacrum._ | |
import stalactite._ | |
import scala.concurrent.Future | |
class Main { | |
trait Terminal[C[_]] { | |
def read: C[String] |
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
abstract class Element(text: String) { | |
def accept(visitor: Element => Unit): Unit = | |
visitor(this) | |
} | |
case class Title(text: String) extends Element(text) | |
case class Text(text: String) extends Element(text) | |
case class Hyperlink(text: String, val url: String) extends Element(text) |