Skip to content

Instantly share code, notes, and snippets.

@szoio
szoio / EventSourcing.scala
Created Feb 23, 2017
Event Sourcing with Free Monads
View EventSourcing.scala
package eventsourcing
import java.time.Instant
import cats._
import cats.data.Coproduct
import cats.free.{Free, Inject}
import cats.implicits._
import doobie.imports._
import fs2.Stream
@szoio
szoio / EventSourcable.scala
Last active Sep 17, 2018
Event Sourcing Interpreter
View EventSourcable.scala
package stephenzoio.kafka_tests.shared.eventsrc
import java.util.UUID
import cats._
import cats.implicits._
import cats.data.{EitherK, WriterT}
import cats.free.Free
import stephenzoio.kafka_tests.shared.free.FreeOp
@szoio
szoio / immutableUpdate.js
Created Nov 11, 2018
Immutable JavaScript object updater (simple implementation)
View immutableUpdate.js
import equal from 'deep-equal'
export function immutableUpdate( obj, change ) {
const keys = Object.keys( change )
if ( keys.length === 0 ) {
return obj
}
const key = keys[ 0 ]
const value = change[ key ]
if ( keys.length === 1 ) {
@szoio
szoio / MonadT.scala
Last active May 25, 2020
Generic Monad Transformer
View MonadT.scala
import cats._
import cats.effect.IO
import cats.implicits._
case class MonadT[F[_], G[_], A](value: F[G[A]])
object MonadT {
implicit def monad[F[_], G[_]](implicit MF: Monad[F], MG: Monad[G], TG: Traverse[G]): Monad[({ type T[A] = MonadT[F, G, A]})#T] = {
type T[A] = MonadT[F, G, A]
new Monad[T] {
View magnolia.scala
import magnolia._
import scala.language.experimental.macros
import scala.util.Try
final case class User(name: String, age: Int, admin: Boolean)
trait CsvDecoder[A] {
def decode(value: List[String]): Either[Throwable, A]
}
@szoio
szoio / shapeless-typeclass.scala
Created Jun 9, 2020
Shapeless Typeclass Example
View shapeless-typeclass.scala
import shapeless._
import scala.{:: => :::}
import cats.implicits._
trait CsvDecoder[A] {
def decode(value: List[String]): Option[A]
}
val columnSplitter = """,(?=([^\"]*\"[^\"]*\")*[^\"]*$)""".r
@szoio
szoio / hlist.scala
Created Jun 9, 2020
Shapeless Intro
View hlist.scala
import shapeless._
val oneHello = 1 :: "hello" :: Nil
val oneHello = 1 :: "hello" :: HNil
final case class User(name: String, age: Int)
val genericUser = Generic[User]
type GenericUserType = genericUser.Repr
View dependent-types.scala
trait DependentValue{
type V
val value: V
}
//object DependentValue {
// def apply[A](a: A): DependentValue { type V = A } = new DependentValue {
// type V = A
// val value = a
// }