import Data.Functor.Yoneda
import Data.Char
import Data.Kind
infixr 5
·
type List :: (Type -> Type) -> Constraint
class List f where
This uses llm.datasette.io and OpenAI. | |
I use `git commit --template` to provide the output from the LLM to Git. This way, if you do not like the results, you | |
can quit your editor and no commit will be made. | |
# Shell function for generating a diff and editing it in your default editor: | |
gcllm() { | |
GIT_DIR="$(git rev-parse --git-dir)" | |
TEMPLATE="$GIT_DIR/COMMIT_EDITMSG_TEMPLATE" |
/* Example of encoding Functor/Applicative/Monad from cats with Dotty 0.15 features. | |
* Derived in part from Cats -- see https://github.com/typelevel/cats/blob/master/COPYING for full license & copyright. | |
*/ | |
package structures | |
import scala.annotation._ | |
trait Functor[F[_]] { | |
def (fa: F[A]) map[A, B](f: A => B): F[B] | |
def (fa: F[A]) as[A, B](b: B): F[B] = |
package demo | |
import cats.{Applicative, Functor, Id, Semigroupal, Traverse} | |
import cats.arrow.FunctionK | |
/** | |
* Type-lifting operation to replace the wildcard type (i.e. _). | |
* | |
* In some cases we end up with code like: List[Option[_]]. This is | |
* fine unless you later need to write code in terms of a particular |
import fs2.concurrent.Queue | |
import cats.implicits._ | |
import cats.effect.Concurrent | |
import cats.effect.concurrent.Ref | |
def groupBy[F[_], A, K](selector: A => F[K])(implicit F: Concurrent[F]): Pipe[F, A, (K, Stream[F, A])] = { | |
in => | |
Stream.eval(Ref.of[F, Map[K, Queue[F, Option[A]]]](Map.empty)).flatMap { st => | |
val cleanup = { | |
import alleycats.std.all._ |
package fpmax | |
import scala.util.Try | |
import scala.io.StdIn.readLine | |
object App0 { | |
def main: Unit = { | |
println("What is your name?") | |
val name = readLine() |
import arrow.Kind | |
import arrow.core.Option | |
import arrow.core.Try | |
import arrow.core.functor | |
import arrow.effects.IO | |
import arrow.effects.fix | |
import arrow.effects.functor | |
import arrow.typeclasses.Functor | |
/* algebras */ |
import scala.util.Try | |
object PathSerializer { | |
trait SerDe[A] { | |
// By using a path dependent type, we can be sure can deserialize without wrapping in Try | |
type Serialized | |
def ser(a: A): Serialized | |
def deser(s: Serialized): A | |
// If we convert to a generic type, in this case String, we forget if we can really deserialize |
I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.
This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
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