This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use this to track the maximum size of a list | |
enum Size: Z, S(prev: Size) | |
def size(list, acc): | |
recur list: | |
[]: acc | |
[_, *t]: size(t, S(acc)) | |
def sort(ord: Order[a], list: List[a]) -> List[a]: | |
Order { to_Fn } = ord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] Main Scala API documentation successful. | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6/com/twitter/algebird-core_2.13/0.13.6.part/algebird-core_2.13-0.13.6.jar.asc | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6/com/twitter/algebird-core_2.13/0.13.6.part/algebird-core_2.13-0.13.6.pom | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6/com/twitter/algebird-core_2.13/0.13.6.part/algebird-core_2.13-0.13.6-javadoc.jar.asc | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6/com/twitter/algebird-core_2.13/0.13.6.part/algebird-core_2.13-0.13.6-sources.jar | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6/com/twitter/algebird-core_2.13/0.13.6.part/algebird-core_2.13-0.13.6-sources.jar.asc | |
[info] published algebird-core_2.13 to /home/oscar/oss/algebird/target/sonatype-staging/0.13.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.stripe.unprotonated | |
import scala.collection.immutable.SortedSet | |
object Graph { | |
/** | |
* Build a DAG by merging individual nodes of type A into merged nodes of type SortedSet[A] | |
*/ | |
final class Dagify[A: Ordering](seed: Set[A], val neighbors: A => Set[A]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Consider a simple recursive function like: | |
* f(x) = if (x > 1) f(x - 1) + x | |
* else 0 | |
* | |
* This function isn't tail recursive (it could be, but let's set that aside for a moment). | |
* How can we mechanically, which is to say without thinking about it, convert this into a stack safe recursion? | |
* An approach is to model everything that happens after the recursion as a continuation, and build up that | |
* continuation in a stack safe manner. Here is some example code: | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bykn.refmap | |
import cats.data.State | |
import cats.effect.Sync | |
import cats.effect.concurrent.Ref | |
import java.util.concurrent.ConcurrentHashMap | |
import cats.implicits._ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// unfortunately | |
// opaque type Fix[F[_]] = F[Fix[F]] | |
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf | |
object FixImpl { | |
type Fix[F[_]] | |
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]] | |
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class MapModule { | |
type K | |
def ordering: Ordering[K] | |
type Map[_] | |
def empty[V]: Map[V] | |
def updated[V](m: Map[V], key: K, v: V): Map[V] | |
def get[V](m: Map[V], key: K): Option[V] | |
def items[V](m: Map[V]): Stream[(K, V)] | |
def remove[V](m: Map[V], key: K): Map[V] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class B { } | |
class Main { | |
public static void main(String[] args) { | |
B strMain = Main.<String>cast("this is not a b"); | |
System.out.println(strMain.toString()); | |
} | |
public static <A extends Object> B cast(A a) { | |
B[] ary = new B[1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_lambda(captured, fn, arity): | |
return { | |
"cap": captured, | |
"fn": fn, | |
"arity": arity, | |
"applied": [], | |
} | |
def apply_lambda(lam, arg): | |
app0 = lam["applied"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bykn.buildcart | |
import cats.{Alternative, Applicative, Id, Eq, Monad, Order, Traverse} | |
import cats.data.{Chain, Const, State} | |
import scala.collection.immutable.SortedSet | |
import cats.implicits._ | |
object BuildCart { | |
trait Hash[A] |