Skip to content

Instantly share code, notes, and snippets.

View Tvaroh's full-sized avatar
😻
Happy programming

Aliaksandr Siamionau Tvaroh

😻
Happy programming
View GitHub Profile
@Tvaroh
Tvaroh / gist:48622f4d989e2bc8366e
Last active August 29, 2015 14:08
Morearty.js releases history
* 0.5.0 - Update to Immutable 3.0.
* 0.4.6-0.4.7 - Maintenance releases.
* 0.4.5 - Update to Immutable 2.5. Make `TransactionContext` mutable.
* 0.4.4 - Update to Immutable 2.3. Add `Binding.toJS` method.
* 0.4.3 - Fix: Morearty.isChanged now checks equality with Sequence.equals.
* 0.4.2 - Moved browserify-shim transform to build script as it applies on each module require.
* 0.4.1 - Fix #22 (index.js and dist/morearty.js are not in npm package).
* 0.4.0 - Normalize dependencies (no need to pass React and Immutable around). New standalone build (thanks to Marat Bektimirov). Fixes #19.
* 0.3.6 - Fix incorrect behavior of `Binding.clear`. Correct `Context.isChanged` when rendering on requestAnimationFrame. Minor improvements.
* 0.3.5 - Fix caching issue.
package io.treev.eventsourcing
import cats.data.Xor
import enumeratum.{CirceEnum, Enum, EnumEntry}
import io.circe.Encoder
import io.circe.generic.auto._
import io.treev.eventsourcing.model.Context
import io.treev.model._
import monix.eval.Task
package com.rms.miu.common.db.slick
import java.time.{Duration, LocalDateTime}
import cats.{Monad, ~>}
object simple {
object common {
/**
* Adapted from
* https://github.com/softwaremill/scala-common/blob/master/tagging/src/main/scala/com/softwaremill/tagging/package.scala
* with added tagging operators, function-first-style tagging, and explicit container-types tagging.
*/
object tag {
type Tag[+U] = { type Tag <: U }
type Tagged[+T, +U] = T with Tag[U]
type @@[+T, +U] = Tagged[T, U]
@Tvaroh
Tvaroh / TransitSvc.js
Last active June 2, 2017 19:40
transit-js bridge to immutable 3.0
define(['transit', 'immutable'], function (Transit, Imm) {
'use strict';
var reader = Transit.reader('json', {
arrayBuilder: {
init: function () { return Imm.List.of().asMutable(); },
add: function (ret, val) { return ret.push(val); },
finalize: function (ret) { return ret.asImmutable(); },
fromArray: function (arr) { return Imm.List(arr); }
},
@Tvaroh
Tvaroh / Session.scala
Last active December 5, 2017 07:55
TODO
import cats.{Monad, StackSafeMonad}
import cats.effect.{IO, LiftIO}
trait Session {
def close(): Unit
}
case class SessionContext[T](exec: Session => IO[T]) {
def runSession(newSession: () => Session): IO[T] = {
@Tvaroh
Tvaroh / CloseableIteratorPublisher.scala
Last active December 7, 2017 13:15
Iterator to Reactive Streams publisher
import org.reactivestreams.{Publisher, Subscriber, Subscription}
import scala.util.control.NonFatal
/** Iterator-based Reactive Streams publisher.
* @param iterator iterator
* @param onDone done callback */
class CloseableIteratorPublisher[T](iterator: Iterator[T], onDone: () => Unit)
extends Publisher[T] {
@Tvaroh
Tvaroh / AsyncPublisher.scala
Created December 21, 2017 14:42
Asynchronous "iterator" to Reactive Streams publisher
import java.util.concurrent.atomic.AtomicReference
import java.util.function.UnaryOperator
import org.reactivestreams.{Publisher, Subscriber, Subscription}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.util.control.NonFatal
class AsyncPublisher[T](next: () => Future[Option[T]],
@Tvaroh
Tvaroh / collectFirst.scala
Last active January 11, 2018 13:26 — forked from Odomontois/collectFirst.scala
collectFirstM using cats
import cats.implicits._
object CollectFirstM {
implicit class CollectFirstMSyntax[F[_], A](val xs: Seq[A]) extends AnyVal {
def collectFirstM[B, M[_]](f: A => M[Option[B]])(implicit M: Monad[M]): M[Option[B]] =
M.tailRecM(xs) {
case x +: rest => f(x).map {
case some@Some(_) => Right(some)
@Tvaroh
Tvaroh / TaskAsync.scala
Last active January 12, 2018 13:35
Korolev's Async instance for Monix Task
implicit object TaskAsync extends korolev.Async[Task] {
override def pureStrict[A](value: A): Task[A] = Task.now(value)
override def pure[A](value: => A): Task[A] = Task.now(value)
override def fork[A](value: => A): Task[A] = Task(value)
override def unit: Task[Unit] = Task.unit
override def fromTry[A](value: => Try[A]): Task[A] = Task.fromTry(value)
override def promise[A]: korolev.Async.Promise[Task, A] = {
val promise = scala.concurrent.Promise[A]()
korolev.Async.Promise(Task.fromFuture(promise.future), a => { promise.complete(a); () })
}