Skip to content

Instantly share code, notes, and snippets.

David Barri japgolly

Block or report user

Report or block japgolly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Quick Tips for Fast Code on the JVM

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

View metamorphism.hs
-- | A “flushing” 'stream', with an additional coalgebra for flushing the
-- remaining values after the input has been consumed. This also allows us to
-- generalize the output away from lists.
:: (Cursive t (XNor a), Cursive u f, Corecursive u f, Traversable f)
=> Coalgebra f b -> (b -> a -> b) -> Coalgebra f b -> b -> t -> u
fstream ψ g ψ' = go
go c x =
let fb = ψ c

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

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
kdrakon / ConsistentHashGroupedStreams.scala
Created Sep 6, 2016
Example of Consistent Hashing for Akka groupBy Streams
View ConsistentHashGroupedStreams.scala
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{Executors, TimeUnit}
import{ActorSystem, Props}
import akka.routing.ConsistentHash
import{Flow, GraphDSL, RunnableGraph, Sink, Source}
import{ActorMaterializer, ClosedShape, ThrottleMode}
import com.kifi.franz.{MessageId, SQSMessage}
gkossakowski /
Last active Jun 19, 2018
Understand Scala's core typechecking rules

Scala's "type T in class C as seen from a prefix type S" with examples


Recently, I found myself in need to precisely understand Scala's core typechecking rules. I was particulary interested in understanding rules responsible for typechecking signatures of members defined in classes (and all types derived from them). Scala Language Specification (SLS) contains definition of the rules but lacks any examples. The definition of the rules uses mutual recursion and nested switch-like constructs that make it hard to follow. I've written down examples together with explanation how specific set of rules (grouped thematically) is applied. These notes helped me gain confidence that I fully understand Scala's core typechecking algorithm.

As Seen From

Let's quote the Scala spec for As Seen From (ASF) rules numbered for an easier reference:

holoed / JsonParser.hs
Last active Mar 31, 2017
Json Parser Example
View JsonParser.hs
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
newtype Fix f = In { out :: f (Fix f) }
type Algebra f a = f a -> a
JasonSwindle / DockerCleanup-Task.json
Last active Oct 7, 2019
A task definition for ECS using MeltWater's Docker Container and Image clean-up containerized script. Please see for more details on correct usage.
View DockerCleanup-Task.json
"containerDefinitions": [
"volumesFrom": null,
"memory": 32,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": true,
"dnsSearchDomains": null,
"portMappings": [],
nponeccop / Unfold.hs
Created Aug 16, 2015
Unfolds, coalgebras and anamorphisms
View Unfold.hs
{-# LANGUAGE DeriveFunctor #-}
import Data.Functor.Foldable
import Data.Function
unfold1 :: Unfold Int [Int]
unfold1 = xana coalgebra1
xana :: Unfoldable b => Coalgebra a b -> Unfold a b
xana = ana
zraffer / package.scala
Last active Apr 26, 2017
a few operations with functors
View package.scala
package object types {
import scala.language.reflectiveCalls
import scala.language.higherKinds
// quantifiers aka (co)ends
type Forall[+F[_]] = { def apply[X]: F[X] }
type Exists[+F[_]] = F[_]
// basic categorical notions
djspiewak /
Created Mar 22, 2015
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

You can’t perform that action at this time.