Skip to content

Instantly share code, notes, and snippets.

View globulon's full-sized avatar
💭
I may be slow to respond.

patterngazer globulon

💭
I may be slow to respond.
View GitHub Profile
@globulon
globulon / Hylo.hs
Created June 10, 2019 14:35
Differences with Scala Implicits
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ConstrainedClassMethods #-}
module Hylo(CoAlgebra(..), Anamorphism(..), Algebra(..), Catamorphism(..)) where
newtype CoAlgebra x u = CoAlgebra {
unfold :: u -> Either () (x, u)
}
class Anamorphism m where
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
import com.graboids.alpha.service.users.app.Application
import com.graboids.alpha.service.users.config.resolveConfig
import com.graboids.config.hocon._
import com.graboids.fp._
import scalaz.NonEmptyList._
import scalaz.ioeffect.console._
import scalaz.ioeffect.{IO, SafeApp, Void}
import akka.http.scaladsl.model.HttpMethod
final case class Cors(domain: String, methods: List[HttpMethod])
trait Isomorphism[Arrow[_, _], A, B] {
def to: Arrow[A, B]
def from: Arrow[B, A]
}
package nl.autotrack.data.batches.metrics
import java.time.format.DateTimeFormatter
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder
import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream
import com.persogroep.aws.kinesis.{AWSStreamProxy, RegionNameIdentification}
import nl.autotrack.data.metrics.raw.{DateFormats, Formats, MetricRequest, OwnerLenses, OwnerTarget, Setting}
import org.apache.spark.SparkConf
@globulon
globulon / Types.scala
Created July 28, 2016 20:26
Type inheritance for KVS injection
import scala.language.higherKinds
//Contract on what can be cached
trait CanBeCached[T]
trait InMemory[T] extends CanBeCached[T]
//Contracts inherited persistable implementations
trait Persistable[T] extends CanBeCached[T]
trait InheritPersistable[T, +R <: InheritPersistable[T, R]] extends Persistable[T] { self: R => }
@globulon
globulon / gist:5570314
Created May 13, 2013 18:24
First attempt to curry a side effect
private static <T> Consumer<T> traceMessage(final String prefix) {
return t -> System.out.println(String.format("%s: %s", prefix, t));
}
final Comparator<Person> compareAsc = Person::ageDifference;
people.stream().min(compareAsc).ifPresent(traceMessage("Younger"));
@globulon
globulon / gist:5549794
Created May 9, 2013 19:15
Monad for input generator in fp in scala
trait Runnable[A] {
def run: A
}
object Delay {
def apply[A](a: => A) = new Runnable[A] {
def run: A = a
}
def map[A, B](r: Runnable[A])(f: A => B): Runnable[B] = new Runnable[B] {
trait PipelineBuilder {
def createStage[I, O](f: I => O) : Stage[I, O]
def link[I, O, P >: O, Q](first: Stage[I, O], second: Stage[P,Q]) : Stage[I, Q]
}
//a pipeline is composed of stages
trait Stage[I, O] extends (I => O) {
owner =>
@globulon
globulon / Possible.scala
Created May 22, 2012 09:43
Possible Solution
trait SequenceValidation[B] {
self =>
def apply[A](seq: Seq[A]): DomainValidation[Seq[B]]
def map[C](f: B => C) = new SequenceValidation[C] {
def apply[A](seq: Seq[A]): DomainValidation[Seq[C]] =
self.apply(seq) map { validSequence => validSequence map f }
}
def flatMap[C](f: B => SequenceValidation[C]) = new SequenceValidation[C] {