Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@non
non / laws.md
Last active Feb 2, 2019
I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala.
View laws.md

Laws

A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.

Some examples:

x.map(id)                 === x
@etorreborre
etorreborre / lawvere.txt
Last active Jun 23, 2016
Lawvere theories and effects
View lawvere.txt
The Category Theoretic Understanding of Universal Algebra: Lawvere Theories andMonads:
- http://www.pps.univ-paris-diderot.fr/~mellies/mpri/mpri-ens/articles/hyland-power-lawvere-theories-and-monads.pdf
- interesting for the historical part on how both concepts were developed
Just do it: simple monadic equational reasoning
- http://www.cs.ox.ac.uk/jeremy.gibbons/publications/mr.pdf
- laws for effects
Lawvere theories made a bit easier
- http://blog.sigfpe.com/2012/02/lawvere-theories-made-bit-easier.html
@guersam
guersam / Hittable.scala
Last active Oct 19, 2015
Generic update without `.copy`
View Hittable.scala
sealed trait Character
case class Player(hp: Int) extends Character
case class Civilian(name: String, hp: Int) extends Character
case class Monster(hp: Int, weakness: String) extends Character
object HittableDemo extends App {
import Hittable.ops._
val c1: Character = Player(1)
assert(c1.hit == Player(0))
View actor-queue-analysis.md

Actor Queue Notes

The first thing to understand is that the head field inside of scalaz.concurrent.Actor is not the "head" of the message queue in any traditional sense of the word. A better description would be "last". The there are no pointers to the head of the queue, which one of the very clever things about this implementation.

Empty Actor

Consider the case where the actor has no outstanding messages. This new message will go into the following code:

  def !(a: A): Unit = {
@djspiewak
djspiewak / streams-tutorial.md
Created Mar 22, 2015
Introduction to scalaz-stream
View streams-tutorial.md

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@johnynek
johnynek / AliceInAggregatorLand.scala
Last active Jun 5, 2020
A REPL Example of using Aggregators in scala
View AliceInAggregatorLand.scala
/**
* To get started:
* git clone https://github.com/twitter/algebird
* cd algebird
* ./sbt algebird-core/console
*/
/**
* Let's get some data. Here is Alice in Wonderland, line by line
*/
@pchiusano
pchiusano / buffer.scala
Created Aug 6, 2014
Buffer type with purely functional API, using a mutable buffer and cheap copy-on-write scheme
View buffer.scala
import java.util.concurrent.atomic._
import collection.mutable.ArrayBuffer
/**
* Buffer type with purely functional API, using mutable
* `ArrayBuffer` and cheap copy-on-write scheme.
* Idea described by Bryan O'Sullivan in http://www.serpentine.com/blog/2014/05/31/attoparsec/
*/
class Buffer[A](id: AtomicLong, stamp: Long, values: ArrayBuffer[A], size: Int) {
@pchiusano
pchiusano / finallytagless.scala
Last active Mar 13, 2018
Finally tagless encoding of GADTs in Scala
View finallytagless.scala
trait ConsoleAlg[F[_]] {
def readLine: F[Option[String]]
def printLine(line: String): F[Unit]
}
trait Console[+A] {
def run[F[+_]](F: ConsoleAlg[F]): F[A]
}
object Console {
@danclien
danclien / scalaz_console_io_free_monad.scala
Last active Aug 29, 2015
Attempt to write a monad for console IO using scalaz's Free monad
View scalaz_console_io_free_monad.scala
:paste
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return}
// Console grammar
sealed trait ConsoleF[+A]
object Console {
case class WriteLine[A](msg: String, o: A) extends ConsoleF[A]
case class ReadLine[A](o: String => A) extends ConsoleF[A]
}