((((((((((((((())))))))))))))))))))))))
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 tech | |
trait Mondoid[T] { | |
def zero: T | |
def append(a: T, b: T): T | |
} | |
object Mondoid { | |
def apply[A](implicit instance: Mondoid[A]): Mondoid[A] = instance | |
} |
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
sealed trait Fruits | |
object Fruits { | |
case class Banana() extends Fruits | |
case class Apple() extends Fruits | |
} | |
// This could be just FruitsBehaviou[-A] | |
trait FruitsBehavior[-A <: Fruits] { | |
def price(a: A): Int |
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 com.telstra.dx.iot.bin.generator | |
import org.scalacheck.Gen | |
import scala.annotation.tailrec | |
import scalaz.{-\/, \/, \/-} | |
import scalaz.syntax.either._ | |
import scalaz.syntax.std.boolean._ | |
// An algebra for a stateful data generation. More or less scalaz.State but not exactly, but focussed on |
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.compat.java8.FutureConverters.toScala | |
// eh.send returns a completable future in Java. we convert it to Scala future | |
// and throttle sending the data to eventhub in azure nicely and easily! | |
private def sendDataInFutureControlled: Seq[EventData] => EventHubClient => Future[Iterator[Void]] = | |
seq => eh => { | |
// We throttle it and send in sequence to make sure that we are not overloading eventhub | |
Future.sequence(seq.grouped(3).map(s => toScala[Void](eh.send(s.asJava)))) | |
} |
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
// Thanks to @adam_evans for this.. and cats documentation as well | |
// This can be a very simple open source... its far better than just about everything out there! | |
def fromCommandLineArguments(args: List[String]) = { | |
args.sliding(2, 2).flatMap(t => ( | |
(t.headOption.flatMap(str => str.startsWith("--").option(str.replace("--", ""))) |@| | |
t.lift(1).flatMap(str => (!str.startsWith("--")).option(str))){(_, _)}).toList).toMap | |
import Types._ |
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.ValidationNel | |
trait Validation[A] { | |
def validate(a: A): ValidationNel[ValidationError, A] | |
} | |
object Validation { | |
implicit def validation[A](implicit a: Validation[A]): Validation[A] = a | |
// Inspired from shapeless docs |
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.syntax.std.option._ | |
import scalaz.{@@, Show, Tag} | |
import scalaz.syntax.show._ | |
trait Tagger[A] { | |
sealed trait Marker | |
final type Type = A @@ Marker | |
def apply(a: A): Type = Tag[A, Marker](a) | |
def unapply(tagged: Type): Option[A] = unwrapped(tagged).some | |
def unwrapped(tagged: Type): A = Tag.unwrap(tagged) |
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 SuperExchange._ | |
import scalaz.std.string._ | |
import scalaz.syntax.validation._ | |
import SuperExchange._ | |
case class SuperExchange(id: ExchangeId, name: Name) | |
object SuperExchange { | |
type ExchangeId = ExchangeId.Type |
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
implicit val validateName: Validation[Name] = | |
_.successNel[ValidationError] | |
implicit val validateExchangeId: Validation[ExchangeId]= | |
_.successNel[ValidationError] |
OlderNewer