Skip to content

Instantly share code, notes, and snippets.

View helenwilliamson's full-sized avatar

Helen Williamson helenwilliamson

  • Triptease
  • United Kingdom
View GitHub Profile

Keybase proof

I hereby claim:

  • I am helenwilliamson on github.
  • I am helenwilliamson (https://keybase.io/helenwilliamson) on keybase.
  • I have a public key ASAusmMyI-_9FVBNEJffqY7s5AjSQIJIrRnafzt1fmZqkwo

To claim this, I am signing this object:

data class Bob(val name: String, val live: Live)
data class Live(val value: Boolean) {
companion object {
fun apply(value: String?): Boolean =
value.let {
if (it.isNullOrBlank()) null else it
}?.toBoolean() ?: false
}
}
/**
* Created by helen on 20/08/15.
*/
object HarryPotterBasket {
val pricingStrategies = List(TwoBooksPricingStrategy)
def calculate(basket: List[HarryPotterSeries]): Double = {
pricingStrategies.map(_.price(basket)).head.price.get
}
@helenwilliamson
helenwilliamson / gist:eacf7e87a9b9c7888f24
Created October 16, 2014 21:19
Scala Dojo on 16th October
import java.io.File
import scala.io.Source
object MarkovChainApp extends App {
val tokenisedText = Source.fromFile(new File(args(0))).mkString.split(" ").map(_.trim)
val wordMap : Map[String, List[String]] = tokenisedText.sliding(2).foldLeft(Map[String, List[String]]().withDefaultValue(List.empty[String])) {
(dict, words) => {
dict.updated(words(0), words(1) :: dict(words(0)) )
@helenwilliamson
helenwilliamson / gist:021c85f912081fd6931f
Created September 19, 2014 06:47
Actor gist from 18th September
import java.util.Date
import javafx.scene.Parent
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import scala.annotation.tailrec
import scala.concurrent.Future
@helenwilliamson
helenwilliamson / gist:8427562
Created January 14, 2014 22:56
Don't forget that .map works on a function. - MutableThings().addStuff will instantiate 1 MutableThings and return the addStuff function for that specific object - t => MutableThings().addStuff(t) returns a function that creates a MutableThings and calls the addStuff function on this new object.
package main.scala
case class MutableThings(var stuff: List[String] = List()) {
println("Creating new MutableThings")
def addStuff(myStuff: String) = {
this.stuff = List(myStuff)
this
}
}