Skip to content

Instantly share code, notes, and snippets.

View jdegoes's full-sized avatar

John A. De Goes jdegoes

View GitHub Profile
@jdegoes
jdegoes / FileSystem.purs
Last active August 29, 2015 14:09
Figuring out the new guard layout rule
reify :: forall eff. ComponentClass (FileSystemTreeProps eff) FileSystemTreeState
reify = createClass spec
{ displayName = "FileSystemTree"
, getInitialState = \_ -> pure {collapsed: true}
, render = \this -> case this.props.files of
(FileType {"type" = "file", name = n}) -> pure $ D.div {}
[D.span {}
[ dataFileIcon
, D.rawText n
]
@jdegoes
jdegoes / bools.purs
Created October 27, 2014 18:53
Lunchtime experiment with booleans
-- booleans as a partition on a set
type Bool a = a -> Either a a
true' :: forall a. Bool a
true' = Right
false' :: forall a. Bool a
false' = Left
not' :: forall a. Bool a -> Bool a
@jdegoes
jdegoes / die-data-types.purs
Last active August 29, 2015 14:07
Death to data types
module Main where
import Debug.Trace
import Prelude (flip, const, id, ($), (+), (<<<), show)
type Tuple a b = forall z. (a -> b -> z) -> z
mkTuple :: forall a b. a -> b -> Tuple a b
mkTuple a b = \f -> f a b
@jdegoes
jdegoes / die-flags-die.md
Created October 8, 2014 17:20
Death to Boolean Flags

Refactoring Booleans to Functions

Boolean parameters are a plague, responsible for non-composable, monolithic functions that never quite do enough, and countless programming bugs:

  • "Oops, meant to pass that as the 2nd boolean flag, not the 1st!"
  • "Oops, accidentally inverted the meaning of that boolean in the implementation!"
  • "Oops, the function isn't flexible enough for my use case, let's add a 6th boolean flag!"
  • "Oops, got the meaning of that boolean flag wrong, time to dig into the source code!"

All boolean parameters should be refactored into functions that effect the change otherwise encoded in the parameter.

@jdegoes
jdegoes / book-outline.md
Created October 6, 2014 23:24
Enterprise Scala

Enterprise Scala

A guide to writing high-performance, robust, Enterprise-grade Scala applications.

Scala is a new language for the JVM that is rapidly spreading beyond tech companies like Twitter, Netflix, and LinkedIn, and into large Enterprises. Engineering teams in companies of all types and sizes are turning to Scala for its strong type system, its extensive ecosystem (Scalaz, Shapeless, Spire), and its seamless interoperability with legacy Java code bases.

While there are many books geared at introducing developers to the Scala programming language, none specifically address the question of what it means to write idiomatic Scala in today’s modern Enterprise. As a large, complex language with many advanced features, there are many ways to write Scala apps, and not all of them were created equal.

Enterprise Scala is the first book to systematize decades of real world, production experience writing large-scale, Enterprise-grade systems in Scala. The result is a comprehensive overview of what idioma

@jdegoes
jdegoes / cogroup.scala
Last active August 29, 2015 14:04
Simple, generic co-grouping with Scalaz
import scalaz._
import Scalaz._
object cogroup {
import \&/._
sealed trait Instr[A] {
def emit: List[A]
}
case class ConsumeLeft [A](emit: List[A]) extends Instr[A]
@jdegoes
jdegoes / orelse.scala
Created June 4, 2014 20:01
Or else operator for Scalaz
implicit class AnyOps[A](value: A) {
def ?: [B](left: Option[B]): A \/ B = left.map(\/-(_)).getOrElse(-\/(value))
}
@jdegoes
jdegoes / scan.scala
Last active August 29, 2015 14:01
scalaz-stream scan
def scan[F[_], A, B](b: B, p: Process[F, A])(f: (B, A) => B): Process[F, B] = {
import Process._
def scan0(b: B, p: Process[F, A]) = scan(b, p)(f)
p match {
case h @ Halt(e) => h
case await : Await[F, Any, A] =>
Process.await[F, Any, B](await.req)(
@jdegoes
jdegoes / scala-type-error.scala
Created May 7, 2014 22:13
Scala error message
[error] found : (slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.LogicalPlan.JoinType, slamdata.engine.LogicalPlan.JoinRel, slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method app
@jdegoes
jdegoes / errors-hk.txt
Created April 28, 2014 21:28
Lack of higher-kinded type inference???
[error] /Users/John/Documents/github/slamdata/slamengine/src/main/scala/slamdata/engine/physical/mongodb/planner.scala:468: type mismatch;
[error] found : slamdata.engine.analysis.fixplate.PhaseE[slamdata.engine.LogicalPlan2,slamdata.engine.PlannerError,Option[slamdata.engine.physical.mongodb.BsonField],Option[slamdata.engine.physical.mongodb.Selector]]
[error] (which expands to) slamdata.engine.analysis.fixplate.PhaseM[[X]scalaz.\/[slamdata.engine.PlannerError,X],slamdata.engine.LogicalPlan2,Option[slamdata.engine.physical.mongodb.BsonField],Option[slamdata.engine.physical.mongodb.Selector]]
[error] required: slamdata.engine.analysis.fixplate.PhaseM[EitherE,slamdata.engine.LogicalPlan2,Option[slamdata.engine.physical.mongodb.BsonField],?]
[error] val AllPhases = (FieldPhase[Unit]).fork(SelectorPhase, ExprPhase) >>> PipelinePhase