This file contains 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
trait PseudoSbt: | |
type Setting[+_] | |
type Key[+_] | |
type Project | |
/** context to extract value of type A from Setting[A]*/ | |
type ValueExtractor | |
/** Location in source file to be used to track definitions*/ | |
type Location |
This file contains 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 lib "org.typelevel::cats-effect:3.5.1" | |
import cats.effect.* | |
import cats.implicits.* | |
object HowToRunJobsInParallel extends IOApp.Simple: | |
def jobConstructor(r: Ref[IO, Long])(jobId: Any) = r | |
.modify(n => (n + 1, n)) | |
.flatMap(v => IO.println(s"Job $jobId processed task $v")) | |
def run = | |
for |
This file contains 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 compiletime.ops.int.S | |
type Nat[n <: Int] = | |
n match | |
case 0 => 0 | |
case S[n] => S[n] | Nat[n] | |
type Octal = Nat[7] | |
object Registers: |
This file contains 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
def flipFlopChain: List[Boolean] => List[Boolean] = | |
case Nil => Nil | |
case a :: rest => | |
val a1 = !a | |
val rest1 = if a1 then flipFlopChain(rest) else rest | |
a1 :: rest1 | |
def chainToString(l: Seq[Boolean]): String = | |
String(l.toArray.map { case true => '1'; case false => '0' }) |
This file contains 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.annotation.targetName | |
import cats.* | |
import cats.implicits.* | |
import cats.data.{StateT, State} | |
trait CRUD: | |
type Obj | |
type Identity | |
type Criteria |
This file contains 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 com.perikov | |
import cats.* | |
import cats.implicits.* | |
import cats.laws.* | |
import org.scalacheck.Arbitrary | |
import org.scalacheck.Prop.forAll | |
import cats.laws.* | |
import cats.laws.discipline.* |
This file contains 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
<html> | |
<head> | |
<script> | |
let counter = 0; | |
let lastCounter = counter; | |
let lastTime = Date.now(); | |
function showFPS() { | |
const elem = document.getElementById("FPS"); | |
const currentTime = Date.now(); |
This file contains 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
factorial[n_] := | |
Block[{$IterationLimit = \[Infinity]}, factorial[n, 1]]; | |
factorial[0, res_] := res; | |
factorial[n_, res_] := factorial[n - 1, n res]; | |
Length @ IntegerDigits @ factorial[100000] // AbsoluteTiming (*{0.96279, 456574}*) | |
Length @ IntegerDigits @ (100000!) // AbsoluteTiming (* {0.050641, 456574} *) |
This file contains 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
enum Maybe[+A]: | |
case Just(a:A) | |
case None | |
given Functor[Maybe]: | |
def [A,B](fa: Maybe[A]).map(f: A ⇒ B): Maybe[B] = | |
import Maybe._ | |
fa match | |
case Just(a) ⇒ Just(f(a)) |
This file contains 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.ClassTag | |
import scala.compiletime._ | |
inline def alloc[T: ClassTag](n: Int) = if n > 0 then new Array[T](n) else error("Array size should be positive") | |
def main(args: Array[String]): Unit = { | |
println(alloc[Int](100).length) | |
alloc[Int](0) // не компилируется | |
} |
NewerOlder