Skip to content

Instantly share code, notes, and snippets.

View fthomas's full-sized avatar

Frank Thomas fthomas

View GitHub Profile
package fix
import scalafix.v1._
import scala.meta._
class v1_2_0 extends SemanticRule("v1_2_0") {
override def fix(implicit doc: SemanticDocument): Patch = {
doc.tree.collect {
case t @ Term.Select(Term.Select(Term.Select(Term.Name("_root_"), Term.Name("io")), Term.Name("chrisdavenport")), Term.Name("log4cats")) =>
Patch.replaceTree(t, "_root_.org.typelevel.log4cats")
@fthomas
fthomas / proof.txt
Last active August 21, 2020 10:32
inference
https://www.umsu.de/trees/#((a%E2%86%92c)%E2%88%A7(b%E2%86%92d))%E2%86%92((a%E2%88%A7b)%E2%86%92(c%E2%88%A7d))
---
A -> C
B -> D
A & B
---
C & D
object AsyncCallbackInstances {
implicit val asyncCallbackAsync: Async[AsyncCallback] = new Async[AsyncCallback] {
override def async[A](k: (Either[Throwable, A] => Unit) => Unit): AsyncCallback[A] =
AsyncCallback((cb: Try[A] => Callback) => Callback(k(r => cb(r.toTry).runNow())))
override def asyncF[A](k: (Either[Throwable, A] => Unit) => AsyncCallback[Unit]): AsyncCallback[A] =
AsyncCallback((cb: Try[A] => Callback) => k(r => cb(r.toTry).runNow()).toCallback)
override def suspend[A](thunk: => AsyncCallback[A]): AsyncCallback[A] =
AsyncCallback.byName(thunk)
isSorted : Ord a => List a -> Bool
isSorted [] = True
isSorted [x] = True
isSorted (x :: t @ (y :: ys)) = x <= y && isSorted t
minElem : Ord a => (l : List a) -> { auto p : isSorted l = True } -> Maybe a
minElem l = head' l
prove : Ord a => (l : List a) -> Maybe (isSorted l = True)
prove [] = Just $ Refl
@fthomas
fthomas / absorbing.scala
Last active August 29, 2015 14:24
Absorbing Semigroup
trait Semigroup[A] {
def op(a1: A, a2: A): A // op is associative
}
trait Monoid[A] extends Semigroup[A] {
def id: A // id is the identity of op: op(a, id) == op(id, a) == a
}
trait SemigroupZero[A] extends Semigroup[A] {
def zero: A // zero is the absorbing element of op: op(a, zero) == op(zero, a) == zero
@fthomas
fthomas / A.scala
Last active August 19, 2019 16:34
implicit value class vs. implicit def + value class
case class A(i: Int)
object A {
implicit class ASyntax(val self: A) extends AnyVal {
def twice: Int = self.i * 2
}
implicit def toASyntax2(a: A): ASyntax2 =
new ASyntax2(a)
}
import Control.Arrow
type IsEq a = (a, a)
splitInterchange :: (Arrow f) => f a1 a2 -> f a2 a3 -> f b1 b2 -> f b2 b3
-> IsEq (f (a1, b1) (a3, b3))
splitInterchange f1 f2 g1 g2 = (lhs, rhs)
where
lhs = (f1 >>> f2) *** (g1 >>> g2)
rhs = (f1 *** g1) >>> (f2 *** g2)
@fthomas
fthomas / laws.scala
Created February 11, 2015 07:54
Laws
trait InvariantLaws[F[_]] {
implicit def F: Invariant[F]
...
}
object InvariantLaws {
apply[F[_]](implicit ev: Invariant[F]): InvariantLaws[F] =
new InvariantLaws { def F = ev }
}
@fthomas
fthomas / FlatMapLaws.scala
Created February 8, 2015 19:58
FlatMapLaws
package cats.laws
import cats.FlatMap
import cats.arrow.Kleisli
import cats.syntax.apply._
import cats.syntax.flatMap._
import cats.syntax.functor._
/**
* Laws that must be obeyed by any [[FlatMap]].

Keybase proof

I hereby claim:

  • I am fthomas on github.
  • I am fthomas (https://keybase.io/fthomas) on keybase.
  • I have a public key whose fingerprint is E8E0 DFA5 ED5B 5323 0316 7A9F CCCF CFC3 1874 C2DA

To claim this, I am signing this object: