Skip to content

Instantly share code, notes, and snippets.

@dnaumenko
dnaumenko / ts
Created January 22, 2021 14:18
tp_sc_3
interface A { kind: "A", propA: string }
interface B { kind: "B", propB: string }
function foo(param: A | B): string {
switch (param.kind) {
case "A":
return 'foo'
case "B":
return 'bar'
}
}
@dnaumenko
dnaumenko / scala
Created January 22, 2021 14:16
tp_sc_2
sealed trait Or
trait Left extends Or
trait Right extends Or
@dnaumenko
dnaumenko / gist:c9c464307fe5ac19feb253b011dea2b5
Created January 22, 2021 14:13
typescript_scala_perspective_1
interface Animal {
suitableFood: "grass"
}
@dnaumenko
dnaumenko / gist:b54ab80e521651bd12a9ce9b69b6eb9b
Created June 9, 2020 08:04
export google docs table to json
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
import com.example.functional.env.catz._
def buildProgram[F[_] : Sync]: F[Unit] = {
import cats.implicits._
for {
_ <- Sync[F].delay(println("Starting"))
_ <- Sync[F].delay(println("Finished"))
} yield ()
}
import com.example.functional.env.catz._
def buildProgram[F[_] : Sync]: F[Unit] = {
import cats.implicits._
for {
_ <- Sync[F].delay(println("Starting"))
_ <- Sync[F].delay(println("Finished"))
} yield ()
}
def initUnsafe[Ctx](value: Ctx): Context[Ctx] = {
Runtime({}, PlatformLive.Default).unsafeRun(Context.init(value))
}
private[env] abstract class CatsInstance {
implicit def emptyRuntime[Ctx](implicit provideEmptyEnv: ProvideEnv[Ctx]): Runtime[Ctx] = {
Runtime[Ctx](provideEmptyEnv.provide, PlatformLive.Default)
}
}
val context = Runtime({}, PlatformLive.Default).unsafeRun(Context.init(ExampleEnv("test")))
implicit val rts: Runtime[Context[ExampleEnv]] = Runtime(context, PlatformLive.Default)
buildProgram[Env[ExampleEnv, ?]].unsafeRunSync(ExampleEnv("test"))
object EnvFinalTaglessTest extends App {
import com.example.functional.env.catz._
def buildProgram[F[_] : Sync]: F[Unit] = {
import cats.implicits._
for {
_ <- Sync[F].delay(println("Starting"))
_ <- Sync[F].delay(println("Finished"))
} yield ()
}