Skip to content

Instantly share code, notes, and snippets.

John A. De Goes jdegoes

Block or report user

Report or block jdegoes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jdegoes
jdegoes / AsyncToIO.scala
Last active Nov 11, 2017
A sketch of an `Async ~> IO`
View AsyncToIO.scala
val AsyncToIO: NaturalTransformation[Async, IO] {
def apply[A](fa: Async[A]): IO[A] = {
for {
ref <- newIORef[Either[Throwable, A]](Left(new Error("No value")))
counter <- IO(new java.util.concurrent.CountDownLatch(1))
_ <- fa.register(v => ref.set(v).flatMap(_ => IO(counter.countDown()))
_ <- IO(counter.await())
v <- ref.get
a <- v match {
case Left(e) => IO.fail(e)
@jdegoes
jdegoes / CLA.md
Created Feb 1, 2017
SlamData Contributor's License Agreement
View CLA.md

Quasar Contributor License Agreement

Thank you for your interest in contributing to the Quasar open source project.

This contributor agreement ("Agreement") describes the terms and conditions under which you may Submit a Contribution to Us. By Submitting a Contribution to Us, you accept the terms and conditions in the Agreement. If you do not accept the terms and conditions in the Agreement, you must not Submit any Contribution to Us.

This is a legally binding document, so please read it carefully before accepting the terms and conditions. If you accept this Agreement, the then-current version of this Agreement shall apply each time you Submit a Contribution. The Agreement may cover more than one software project managed by Us.

1. Definitions

@jdegoes
jdegoes / example.ejson
Created Jan 19, 2017
EJSON: Extended JSON
View example.ejson
{
"string-key": 1,
{1: "non-string-key"}: true,
"metadata-on-key" @ true : "metadata-on-value" @ [1, 2, "metadata-on-metadata" @ null]
}
@jdegoes
jdegoes / IOTask.scala
Last active Nov 11, 2017
Pedagogical synchronous and asynchronous effect monads in Scala.
View IOTask.scala
case class IO[A](unsafePerformIO: () => A) { self =>
def map[B](ab: A => B): IO[B] =
IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =
IO(() => afb(unsafePerformIO()).unsafePerformIO())
def attempt: IO[Either[Throwable, A]] =
IO(() => try { Right(unsafePerformIO()) } catch { case t : Throwable => Left(t) })
def forkIO: Task[A] = Task(f => IO(unsafePerformIO = () => {
new java.lang.Thread {
override def run: Unit = {
@jdegoes
jdegoes / SeqPar.purs
Created Oct 27, 2016
Free applicative in free monad
View SeqPar.purs
-- A sequential series of parallel program fragments in `f`:
type SeqPar f a = Free (FreeAp f) a
liftFA :: forall f a. f a -> SeqPar f a
liftFA = pure >>> pure
liftSeq :: forall f a. Free f a -> SeqPar f a
liftSeq fa = foldFree fa liftFA
liftPar :: forall f a. FreeAp f a -> SeqPar f a
View Applied-FP-with-Scala.md

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
View Advanced-FP-with-Scala.md

Integers

// `Tuple[Natural, Natural]`
case class Integer(pos: Natural, neg: Natural) { self =>
  def unary_- = copy(neg, pos)
  def + (that: Integer): Integer = Integer(self.pos + that.pos, self.neg + that.neg)
  def - (that: Integer): Integer = this + (-that)
  def * (that: Integer): Integer = Integer(
@jdegoes
jdegoes / FreeMonad.scala
Created Aug 21, 2016
A pedagogical free(er) monad in 23 lines of Scala
View FreeMonad.scala
sealed trait Free[F[_], A] { self =>
final def map[B](ab: A => B): Free[F, B] = Free.flatMap(self, ab andThen (Free.point[F, B](_)))
final def flatMap[B](afb: A => Free[F, B]): Free[F, B] = Free.flatMap(self, afb)
final def interpret[G[_]: Monad](fg: F ~> G): G[A] = self match {
case Free.Point(a0) => a0().point[G]
case Free.Effect(fa) => fg(fa)
case fm : Free.FlatMap[F, A] =>
val ga0 = fm.fa.interpret[G](fg)
ga0.flatMap(a0 => fm.afb(a0).interpret[G](fg))
}
@jdegoes
jdegoes / IO.scala
Created Aug 9, 2016
A pedagogical implementation of the IO monad in Scala in 14 LOC
View IO.scala
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
object IO {
@jdegoes
jdegoes / Advanced Functional Programming in Scala Training - ScalaWorld 2016.md
Created Jul 21, 2016
Advanced Functional Programming in Scala Training - ScalaWorld 2016
View Advanced Functional Programming in Scala Training - ScalaWorld 2016.md
  1. Kiss type confusion goodbye as you learn to understand complex type signatures: T[_[_, _], _], T[({type λ[A]=F[A, K]})#λ].
  2. Level up your ability to write higher-order functions and define combinators to construct larger programs from smaller ones
  3. Learn how you can use rank-N types to program at a higher-level of abstraction, with strong correctness guarantees
  4. Discover how existentials help you compose functionality without exploding the size of type signatures
  5. Master type classes to generate generic, testable code without the tangling and non-local reasoning of inheritance
  6. Use "functional design patterns" like a boss, including functors, applicatives, monads, profunctors, monoids, and others
  7. Have your immutable cake and eat it too with "optics" that let you manipulate complex data structures with ease
  8. Traverse your own data structures without writing any recursive code through powerful, composable, generic recursion schemes
  9. Model effects with powerful, purely functional techniq
You can’t perform that action at this time.