Skip to content

Instantly share code, notes, and snippets.

View zainab-ali's full-sized avatar

Zainab Ali zainab-ali

View GitHub Profile
@zainab-ali
zainab-ali / pull-no-params.scala
Last active July 10, 2023 19:07
Simplified pull free monad without type parameters or overt reference to monads
enum Pull {
case Done
case Output(name: String)
case UnconsThen(pull: Pull, f: Option[(String, Pull)] => Pull)
case Then(pull: Pull, next: () => Pull)
}
import Pull._
val done = Done
def single(name: String) = Output(name)
@zainab-ali
zainab-ali / pull.scala
Created July 10, 2023 18:43
Basic pull free monad for pure infinite streams
enum Pull[A] {
case Pure[A](value: A) extends Pull[A]
case Output(name: String) extends Pull[Unit]
case Uncons[A](pull: Pull[A]) extends Pull[Option[(String, Pull[A])]]
case FlatMap[A, B](pull: Pull[A], f: A => Pull[B]) extends Pull[B]
}
import Pull._
val done: Pull[Unit] = Pure(())
def single(name: String): Pull[Unit] = Output(name)
@zainab-ali
zainab-ali / game.scala
Last active April 1, 2017 18:49
Event Handlers and State combinations
package game
/** Game logic:
*
* The game map is a tiled grid. Each tile has something on it.
*
* Actions:
* When a citizen is clicked on, they can be told to do something.
* At the moment, they can only chop wood.
*
@zainab-ali
zainab-ali / recordWithTuples.scala
Created March 31, 2017 21:03
Zip record with tuples as values
package foo
import shapeless._
import shapeless.labelled.FieldType
import shapeless.ops.hlist._
/** This example zips two hlists together based on their keys and part of their values
*
*
* A left HList of type FieldType[Key, (A, LB)] :: LTail is zipped with a right HList which contains FieldType[Key, (A, RB)]
@zainab-ali
zainab-ali / refute.scala
Created March 23, 2017 14:16
or and refute
trait Refute[A]
object Refute {
implicit def ambiguous1[A](implicit ev: A): Refute[A] = new Refute[A] {}
implicit def ambiguous2[A](implicit ev: A): Refute[A] = new Refute[A] {}
implicit def refute[A]: Refute[A] = new Refute[A] {}
}
object TestRefute {
trait Foo
object gist {
import shapeless._
trait Semigroup[A] {
def combine(a0: A, a1: A): A
}
implicit final class SemigroupCombineOps[A](a0: A)(implicit S: Semigroup[A]) {
def combine(a1: A): A = S.combine(a0, a1)
@zainab-ali
zainab-ali / drone.scala
Created February 26, 2017 18:45
drone dynamic
package drone
import fs2._
import java.time.Instant
import java.util.UUID
object Time {
def local: Task[Instant] = Task.delay(Instant.now())
}
@zainab-ali
zainab-ali / symbols.md
Last active June 7, 2016 01:06
Cats symbols list
Symbol Name Typeclass import
` @ ` Cartesian Builder
=== Equals Eq cats.syntax.eq._
=!= Not Equals Eq cats.syntax.eq._
` + ` Semigroup plus
<+> SemigroupK combine SemigroupK cats.syntax.semigroupk._
~> Natural transformation N/A cats._
Bottom N/A cats._
Top N/A cats._
@zainab-ali
zainab-ali / reader.scala
Last active May 22, 2016 14:55
Local functions on the Reader
//local defined for GlobalEnv => Option[LocalEnv]
def localOption[LocalEnv, GlobalEnv, A](r: Reader[LocalEnv, A])(f: GlobalEnv => Option[LocalEnv]): Reader[GlobalEnv, Option[A]] =
Reader(globalEnv => f(globalEnv).map(r.run))
//generalization of the above in terms of Functors
def localF[F[_], A, AA, B](r: Reader[A, B])(f: AA => F[A])(implicit F: Functor[F]): Reader[AA, F[B]] =
Reader(aa => f(aa).map(r.run))
//generalization of the above in terms of Kleislis
def localFK[F[_], A, AA, B](r: Kleisli[Id, A, B])(f: AA => F[A])(implicit F: Functor[F]): Kleisli[F, AA, B] =
;; the package manager
(require 'package)
(setq
use-package-always-ensure t
package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("melpa" . "http://melpa.org/packages/")))
(package-initialize)
(when (not package-archive-contents)