Skip to content

Instantly share code, notes, and snippets.

View emilypi's full-sized avatar
🥝
hot girl summer

Emily Pillmore emilypi

🥝
hot girl summer
View GitHub Profile
@emilypi
emilypi / SkipList.java
Created May 13, 2015 03:35
Evidence that I'm not lost in the world of bananas, envelopes, lenses and barbed wire.
package interviewDS;
/**
* @author EmilyPillmore
*
* Naive base indexed implementation of the SkipList data structure
* Average Worst case
* Space O(n) O(n log n)
* Search O(log n) O(n)
* Insert O(log n) O(n)
@emilypi
emilypi / Either.java
Created July 2, 2015 02:33
Work samples
package functionaljava.Data;
import functionaljava.Data.List;
import java.util.function.*;
abstract interface Either<A, B> {
abstract <T> T foldEither(final Function<? super A, ? extends T> f, Function<? super B,? extends T> g);
abstract List<Either<A, B>> lefts(List<Either<A, B>> xs);
@emilypi
emilypi / TaggedUnion.sc
Created February 7, 2017 19:33
Generating fully qualified class instance from Tagged Union types with an associated Generator
trait Instantiator[+A] {
def apply(): A
}
object Instantiator {
def apply[A](create: => A): Instantiator[A] = new Instantiator[A] {
def apply(): A = create
}
}
@emilypi
emilypi / Kinds.scala
Last active May 8, 2017 07:17
Higher-Functors of degree 0-3. Natural transformations are lax 2-Functors. Modifications lax 3-Functors
package misc
import scala.language.higherKinds
import scala.util.{Try, Success}
import scala.annotation.tailrec
object Kinds extends App {
trait Functor[F[_]] {
import scala.annotation.tailrec
/**
* Created by emilypi on 5/17/17.
*/
trait Stream[+A] {
import Stream._
def head: () => A
@emilypi
emilypi / fold_Fix.scala
Last active September 6, 2017 01:07
Cata's, Phi's, Mu's Oh My's
package com.emilypi.scalaupnorth.fold
/**
* Created by emilypi on 5/18/17.
*/
case class Mu[F[_]](unFix: F[Mu[F]])
@emilypi
emilypi / Mu.scala
Created December 15, 2017 20:52
Cows go Muuu
package cohomolo.gy.generalized
import scalaz.Prelude.{<~<, IsCovariant}
import scalaz.data.{As, Identity, ~>, ∀}
//final case class Mu[F[_]](unMu: Algebra[F, ?] ~> Identity)
trait MuModule {
type Mu[F[_]]
trait CodensityModule {
type Codensity[M[_], A]
def abs[M[_], A](c: Codensity[M, A])(implicit M: Monad[M]): M[A]
def rep[M[_], A](ma: M[A])(implicit M: Monad[M]): Codensity[M, A]
}
private[data] object CodensityImpl extends CodensityModule with CodensityInstances {
@emilypi
emilypi / FreeCodensity.hs
Created January 10, 2018 20:44
Codensity FreeLike instance
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Codensity where
newtype Codensity m a = Codensity { runCodensity :: forall b. (a -> m b) -> m b }
abs :: Monad m => (a -> m b) -> Codensity m a -> m b
abs k (Codensity c) = c k
@emilypi
emilypi / FFree.scala
Created January 13, 2018 19:12
FFree
sealed abstract class FFree[F[_], A] {
def map[B](f: A => B): FFree[F, B] =
flatMap[B](a => FFree.pure[F, B](f(a)))
def flatMap[B](k: A => FFree[F, B]): FFree[F, B] =
this match {
case FFree.Pure(a) => k(a)
case FFree.Impure(ff, rs) => FFree.impure(ff, rs.:+(Kleisli.wrapKleisli(k)))
}