This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "3.1.1" | |
// let's start with basic functor because all monads in scala have to be functors to work | |
// within a for-comprehension (because it desugars to flatMap + map chain) | |
// F[_] represents any concrete type parameterised with a single type (a type constructor), ie List, Option | |
trait Functor[F[_]]: | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
// define a correct interface for a Monad that extends that Functor, Monad is just | |
// two functions: pure (return in hs) and flatMap (bind in hs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package analytics | |
import analytics.ChartJs.ChartJsConfig | |
import logging.loggerStream | |
import org.apache.batik.transcoder.{SVGAbstractTranscoder, TranscoderInput, TranscoderOutput} | |
import org.apache.batik.transcoder.image.{ImageTranscoder, PNGTranscoder} | |
import org.graalvm.polyglot.{Context, EnvironmentAccess, HostAccess, PolyglotAccess, Source, Value} | |
import org.slf4j.LoggerFactory | |
import zio.blocking.Blocking | |
import zio.stream._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.reflect.runtime.universe.TypeTag | |
import shapeless._ | |
object LazyTypeTagGuardTest { | |
case class Whatever() | |
type X | |
def f[A](xd: A)(implicit ev: Lazy[TypeTag[A]]) = ev.value.tpe.toString |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:102) | |
at java.lang.ClassLoader.getClassLoader(Target_java_lang_ClassLoader.java:1510) | |
at java.lang.Package.getPackage(Package.java:280) | |
at scala.reflect.runtime.JavaMirrors$JavaMirror.packageNameToScala(JavaMirrors.scala:939) | |
at scala.reflect.runtime.JavaMirrors$JavaMirror.$anonfun$scala$reflect$runtime$JavaMirrors$$makeScalaPackage$1(JavaMirrors.scala:951) | |
at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$$makeScalaPackage(JavaMirrors.scala:948) | |
at scala.reflect.runtime.JavaMirrors.missingHook(JavaMirrors.scala:1355) | |
at scala.reflect.runtime.JavaMirrors.missingHook$(JavaMirrors.scala:1348) | |
at scala.reflect.runtime.JavaUniverse.missingHook(JavaUniverse.scala:18) | |
at scala.reflect.internal.Mirrors$RootsBase.universeMissingHook(Mirrors.scala:82) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name" : "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", | |
"allDeclaredConstructors" : true, | |
"allPublicConstructors" : true, | |
"allDeclaredMethods" : true, | |
"allPublicMethods" : true, | |
"allDeclaredClasses" : true, | |
"allPublicClasses" : true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.{Effect, IO} | |
import cats.syntax.flatMap.toFlatMapOps | |
import cats.syntax.functor.toFunctorOps | |
import fs2.StreamApp.ExitCode | |
import fs2.{Pipe, Scheduler, Stream, StreamApp} | |
import io.circe.Json | |
import io.circe.jawn.CirceSupportParser | |
import jawn.Facade | |
import jawnfs2._ | |
import org.http4s.client.Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Position = (Int, Int) | |
type State = Set[Position] | |
def gameOfLife(state: State): Stream[State] = | |
if (state.isEmpty) Stream.empty | |
else state #:: gameOfLife(nextFrom(state)) | |
def nextFrom(state: State) = { | |
for { | |
field <- getFieldsFromState(state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalameter._ | |
object FactorialRunner { | |
def fact(v: BigInt): BigInt = { | |
def recFact(v: BigInt, acc: BigInt): BigInt = | |
if (v == 1) acc else recFact(v - 1, acc * v) | |
recFact(v, 1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MatchError extends Error { | |
} | |
function match<T, S>(value:T) { | |
let result:(_:T)=>S; | |
const context = { | |
caseOf(predicate:(value:T) => boolean, payload:(_:T)=>S) { | |
if (!result && predicate(value)) result = payload; | |
return context; | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Specification { | |
type Spec[-A] = A => Boolean | |
implicit class SpecOps[A](_this: Spec[A]) { | |
def and(that: Spec[A]) = (item: A) => _this(item) && that(item) | |
def or(that: Spec[A]) = (item: A) => _this(item) || that(item) | |
def not = (item: A) => !_this(item) | |
} |