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.annotation.targetName | |
import cats.* | |
import cats.implicits.* | |
import cats.data.{StateT, State} | |
trait CRUD: | |
type Obj | |
type Identity | |
type Criteria |
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 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 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
<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 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
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 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
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 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.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) // не компилируется | |
} |
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
// Тест текущего компилятора Scala3/Dotty и освоение возможностей | |
// Где взять, как пользоваться VSCode в качестве IDE и | |
// дока по языку -- здесь: https://dotty.epfl.ch/docs/index.html | |
/** Основыные алгебраические структур (без законов) | |
*/ | |
object AlgebraicStructures { | |
trait Semigroup[T] { | |
def op(a: T, b: T): T |
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
/** | |
* Не уверен, что это то, что нужно, но это самое общее решение | |
* Никак не опираемся на стандартную библиотеку | |
* У него, возможно или наверняка, будут проблемы с боксингом, но идея такая. Дальше можно | |
* запинать для производительности | |
* | |
* @see https://gist.github.com/p-pavel/2708ee0e7f5beac0a71551bfd885ef67 | |
*/ | |
object CustomCoercion { |
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
trait HList { | |
def ::[A](x: A): A :: this.type | |
} | |
trait ::[+Head, +Tail <: HList] extends HList { | |
val head: Head | |
val tail: Tail | |
def ::[A](x: A): A :: this.type = HCons(x,this) | |
} | |
final case class HCons[+Head, +Tail <: HList](head: Head, tail: Tail) extends (Head :: Tail) { | |
override def toString: String = s"$head :: $tail" |
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
trait IncrementDecrement[F[_]] { // Входы/выходы приложения инкремента-декремента | |
val increment: Stream[F,Unit] // Поток заявок на инкремент | |
val decrement: Stream[F,Unit] // Поток заявок на декремент | |
val total: Pipe[F,Int, INothing] // Переработка текущих значений в чистые побочные эффекты | |
} | |
object Logic { | |
import scala.concurrent.duration._ | |
// Как работать с IncrementDecrement | |
def run[F[_]:Concurrent: Timer](app: IncrementDecrement[F]): Stream[F,INothing] = { |