Skip to content

Instantly share code, notes, and snippets.

public class WreckedCast {
static <P, PP extends Parametric<P>> PP wreckedCast(Parametric<? extends Parametric<P>> ppp) {
return (PP) ppp.extract();
public static void main(String[] args) {
// java.lang.ClassCastException: WreckedCast$Parametric$$Lambda$1/1607521710 cannot be cast to java.lang.String
public class ExceptionalExceptionHandling {
public static void main(String[] args) {
ThrowingSupplier<IllegalStateException, String> wellTyped = () -> {
throw new IllegalStateException();
ThrowingSupplier<RuntimeException, String> wellTypedButUnnecessary = () -> {
jnape /
Created Sep 3, 2016
General recursion with Elgot algebras
import com.jnape.palatable.lambda.adt.Either;
import com.jnape.palatable.lambda.functions.Fn3;
import com.jnape.palatable.lambda.functor.Functor;
import com.jnape.palatable.lambda.functor.builtin.Identity;
import java.util.function.Function;
import static com.jnape.palatable.lambda.adt.Either.left;
import static com.jnape.palatable.lambda.adt.Either.right;
jnape /
Last active Mar 12, 2016
Java8 invokeinterface type-unification bug
package example;
import java.util.Optional;
class Foo {}
interface Bar {
String barMethod();
public class TypeUnifailcation extends Foo implements Bar {
jnape /
Last active Aug 29, 2015
Continuation-like iterable type
package com.jnape.palatable.lambda.applicative;
import com.jnape.palatable.lambda.functions.MonadicFunction;
import static;
public interface BiFunctor<A, B> {
default <C> BiFunctor<C, B> biMapL(MonadicFunction<? super A, ? extends C> fn) {
jnape / List.hs
Created Dec 15, 2014
Haskell's missing core type classes
View List.hs
module MissingTypeClassesIntegration.List where
import MissingTypeClasses
import Prelude hiding (foldl, foldl1, foldr, foldr1, map, filter, zip)
instance RecursiveDataStructure [] where
unit = []
cons = (:)
instance LeftFoldable [] where
jnape / gist:6329963
Created Aug 24, 2013
Suggested TravisCI CSS changes for better scrolling experience
View gist:6329963
Change: position: absolute; to position: fixed;
Change: top: -40px; to top: 0;
#left, #right:
Change: position: relative; to position: fixed;
Remove: position: relative;
Add: margin-left: 381px;
jnape /
Created Aug 6, 2013
ThoughtWorks P2, Issue 03 Puzzle Solution
% The person who has to deploy to Mobile is not Max or Sam
% Neither Max or Charlie are fans of Copying Files
% The one who deploys quarterly does so to a Mobile target
% Andy deploys weekly
% The person making use of a third party PAAS is not Andy or Charlie
% Sam is either the Copying Files or the System Package enthusiast
% The person who makes VM Images is not Charlie and doesn’t own deploy to a PAAS
% The person who deploys to the PAAS is does so more frequently than the person who deploys to the Desktop
% Of the System Packaging fan and Charlie, one deploys monthly and the other deploys to Mobile
% The person who deploys to the IAAS is not Max
jnape /
Created Jun 12, 2013
Python Decorator that automatically unstubs all Mockito stubs after each test case
from unittest2 import TestCase
from mockito import when, unstub
from uuid import UUID
import uuid
def use_mocking(test_suite):
wrapped_tearDown = test_suite.tearDown if 'tearDown' in dir(test_suite) else lambda self: True
def tearDown(self):
jnape / Brainfuck.scala
Last active Dec 15, 2015
A Brainfuck interpreter written in Scala
View Brainfuck.scala
package com.thoughtworks.futureeither
import scala.collection.mutable
abstract sealed class LoopOutcome {
def endOrElse(fn: => Any) = this match {
case Repeat() => fn
case _ =>