Skip to content

Instantly share code, notes, and snippets.

View afsalthaj's full-sized avatar

Afsal Thaj afsalthaj

View GitHub Profile
package com.telstra.dxmodel.api.interop
import cats.data.{EitherT, Writer, WriterT}
import cats.free.Free
import scala.util.Try
import cats.implicits._
import cats.{Monad, ~>}
import com.telstra.dxmodel.api.interop
import scalaz.zio.IO
// This might look really simple, but people often get carried away validationNel (applicative) and disjunctions (monad) ended up having only errors (or a error) or a valid right.
// However we can go one step forward. Maximum error accumulation + Max computation (try hard, try hard)
import scalaz._, Scalaz._
def process1(int: Int): Int = throw new Exception("errors")
def process2(int: Int) : Int = int + 1
def process3(int: Int) : Int = int + 2
package delta
// Use shows instance instead of toString on even primitives.
import shapeless.{::, HList, HNil, LabelledGeneric, Lazy, Witness}
import shapeless.labelled.FieldType
import cats.evidence.{As, Is}
import Delta.Meta
import cats.Eq
import cats.data.Ior
import cats.implicits._
import Delta.{Changed, Deleted, DeltaOp, New}
import scalaz.\&/
import scalaz.\&/.{Both, That, This}
import scalaz.{Name => _, _}
import Scalaz._
case class Bla(someValue: String)
case class MajorResource1(bla: Bla, name: String)
// Trying to find case class names using shapeless involving a tree structure
import shapeless.{::, HList, HNil, LabelledGeneric, Lazy, Witness}
import shapeless.labelled.FieldType
import cats.evidence.{As, Is}
/**
*
* {{{
case class BadVal(value: String) extends AnyVal
import scalaz.{Scalaz, _}
import Scalaz._
// Thanks to https://underscore.io/blog/posts/2017/03/29/free-inject.html
object CombineFreeInScalaz {
sealed trait Logging[A]
case class Info(s: String) extends Logging[Unit]
import java.io.File
import scalaz.{Id, Monad}
// Finally tagless approach
trait FileOperation[F[_], A] {
def makeDir(d: File, x: A): F[A]
def createFile(d: File, x: A): F[A]
package io.atlassian.aws
import java.io.File
import scalaz.{Free, Functor}
sealed trait FileActionOp[A]
case class Pure[A](x: A) extends FileActionOp[A]
case class MakeDir[A](d: File, x: A) extends FileActionOp[A]
case class CreateFile[A](d: File, x: A) extends FileActionOp[A]

Code Hint (please don't look at this until you solve it yourself)

So, here goes my code snippet thinking. Looking at the problem, it feels like a program should return another program. In fact, in our case we have lots of instances of "program" and we need to return/pass these programs.

So lets go ahead and create a program that should be returned. In our case, the main one is Notification.

{
 sealed trait Notification[A]
import scalaz.Free
sealed trait Notification[A]
case class SendEmail(s: String) extends Notification[Unit]
case class SendMessage(s: String) extends Notification[Unit]
case class NothingJustLog(s: String) extends Notification[Unit]
sealed trait Table[Unit]