This file contains hidden or 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
trait InvariantLaws[F[_]] { | |
implicit def F: Invariant[F] | |
... | |
} | |
object InvariantLaws { | |
apply[F[_]](implicit ev: Invariant[F]): InvariantLaws[F] = | |
new InvariantLaws { def F = ev } | |
} |
This file contains hidden or 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
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) |
This file contains hidden or 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
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) | |
} |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
This file contains hidden or 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 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") |
OlderNewer