Skip to content

Instantly share code, notes, and snippets.

@DamianReeves
DamianReeves / BreadthFirst.scala
Created May 16, 2023 19:57
ZIO Breadth first
sealed trait State
case object PullOuter extends State
case class PullInner(
stream: ZIO[R1, Option[Nothing], Chunk[Option[B]]],
chunk: Chunk[Option[B]],
index: Int,
finalizer: Exit[Any, Any] => UIO[Any]
) extends State
@DamianReeves
DamianReeves / RestrictionAnalyzer.fs
Created May 12, 2023 15:45
F# Analyzer to Restrict language
module RestrictionAnalyzer
open FSharp.Analyzers.SDK
open FSharp.Compiler.Text
open FSharp.Compiler.Syntax
let hasTypeInNamespace (target:SynModuleOrNamespace): Message option =
match target with
| SynModuleOrNamespace(kind = SynModuleOrNamespaceKind.DeclaredNamespace; decls = decls) ->
let hasTypes =
@DamianReeves
DamianReeves / Idea01.scala
Last active January 4, 2023 19:38
Morphir Macro ideas
trait PersonModule {
trait Person { def name: String; def age: Int }
}
trait ModuleDef[T] {
val value: T
}
// val myModule: ModuleDef[PersonModule] =
❯ scala-cli package . --native-image --graalvm-jvm-id system

Downloading: Component catalog from www.graalvm.org
Processing Component: Native Image
Downloading: Component native-image: Native Image from github.com
I/O error occurred: Remote host terminated the handshake
Error: os.SubprocessException: CommandResult 2
@DamianReeves
DamianReeves / GitOps.scala
Last active July 20, 2022 13:21
Generate morphir-ir
import upickle.default._
object GitOps {
lazy val gitExe = if (scala.util.Properties.isWin) "git.exe" else "git"
implicit val GivenOsPathReader: ReadWriter[os.Path] =
readwriter[String].bimap(_.toString, os.Path(_))
final case class GitCloneOptions(
repository: String,
@DamianReeves
DamianReeves / ValueCase.scala
Created April 4, 2022 22:24
Scala Type Lambda Trick
import zio.prelude._
sealed trait ValueCase[+TA,+VA,+Self] { self => }
object ValueCase {
// Would have cases defined
type Curry[A[+_, +_, +_], T, U] = { type Result[+V] = A[T, U, V] }
implicit def ValueCaseForEach[TA, VA]: ForEach[Curry[ValueCase, TA, VA]#Result]] = ???
}
@DamianReeves
DamianReeves / Field.scala
Created July 31, 2021 01:10
Field Properties
package datadictionary
import datadictionary.Field.Modifier
type AnyField = Field[?, Nothing, Nothing]
type AnyFieldHavingKeyOf[K <: Field.FieldKey] = Field[K, Nothing, Nothing]
final case class Field[Key <: Field.FieldKey, +A, +Attribs](key: Key) extends Serializable:
def asConstant(using Attribs <:< Modifier.Assignable) = ???
override def toString: String = key
@DamianReeves
DamianReeves / Error.md
Last active August 14, 2020 11:33
Mill Build issue

Exception in thread "MillServerActionRunner" java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at mill.define.Module$Internal.$anonfun$reflect$4(Module.scala:73) at scala.collection.ArrayOps$WithFilter.map(ArrayOps.scala:90) at mill.define.Module$Internal.reflect(Module.scala:64) at mill.define.Module$Internal.reflectAll(Module.scala:76)

package zio.integration.stream
import zio._
import zio.stream._
object StreamOps extends StreamOps
trait StreamOps {
implicit class ZStreamOps[R,E,A](self:ZStream[R,E,A]) {
def split(p : A => UIO[Boolean]) : ZManaged[R, E, (ZStream[R,E,A],ZStream[R,E,A])] =
@DamianReeves
DamianReeves / build.gradle
Created January 19, 2019 16:00
Declaring Custom Scala Compiler Plugin configuration
configurations {
scalaCompilerPlugin
}
dependencies {
// Use Scala 2.11 in our library project
compile 'org.scala-lang:scala-library:2.12.6'
compile 'io.estatico:newtype_2.12:0.4.2'
scalaCompilerPlugin 'org.scalamacros:paradise_2.12.6:2.1.1'