Skip to content

Instantly share code, notes, and snippets.

View mperry's full-sized avatar

Mark Perry mperry

View GitHub Profile
@mperry
mperry / gist:8534788
Created January 21, 2014 05:15
This is an attempt to explore the duality of fold and unfold
Haskell definitions:
unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
foldr :: (a -> b -> b) -> b -> [a] -> b
If I reverse the arrows on unfoldr
dual(unfoldr) :: [a] -> (Maybe (a, b) -> b) -> b
I think I need to show the type isomorphism (a -> b -> b) -> b is equivalent to Maybe (a, b) -> b, which is equivalent to
(a -> b -> b) == Maybe(a, b)
@mperry
mperry / IdTest.java
Last active August 29, 2015 13:58
Exploring equals and hash code for Java 8 Lamdas
package com.github.mperry;
import org.junit.Test;
import java.util.function.Function;
import static org.junit.Assert.assertTrue;
/**
* Created by MarkPerry on 3/04/2014.
@mperry
mperry / jvm.bat
Last active August 29, 2015 13:58
Switches java versions and add the new JAVA_HOME to the front of the PATH.
@echo off
set VERSION=%1
call setEnvVar JAVA_HOME JAVA%VERSION%_HOME
echo JAVA_HOME=%JAVA_HOME%
@mperry
mperry / bugImplicitBoxing.groovy
Last active August 29, 2015 13:59
Implicit boxing with the extension module does not seem to work with Groovy 2.2.0, ok with 2.2.2
@GrabResolver('https://oss.sonatype.org/content/repositories/snapshots/')
@Grab('com.github.mperry:functionalgroovy-main:0.5-SNAPSHOT')
import groovy.transform.TypeChecked
import org.junit.Test
import static junit.framework.Assert.assertTrue
@TypeChecked
class StreamTest {
@mperry
mperry / listMonadTest.groovy
Last active August 29, 2015 13:59
Testing a ListMonad and the extension methods added to List from the monad.
// taken from https://github.com/mperry/functionalgroovy/blob/master/test-extensions/src/test/groovy/com/github/mperry/fg/ListMonadExtensionTest.groovy
//@GrabResolver('https://oss.sonatype.org/content/groups/public')
@GrabResolver('https://oss.sonatype.org/content/repositories/snapshots/')
@Grab('com.github.mperry:functionalgroovy-main:0.5-SNAPSHOT')
import fj.F
import fj.F2
import groovy.transform.TypeChecked
import groovy.transform.TypeCheckingMode
import org.junit.Test
@mperry
mperry / optionMonadTest.groovy
Created April 14, 2014 04:06
Testing the option monad.
// from https://github.com/mperry/functionalgroovy/blob/master/test-extensions/src/test/groovy/com/github/mperry/fg/OptionMonadExtensionTest.groovy
//@GrabResolver('https://oss.sonatype.org/content/groups/public')
@GrabResolver('https://oss.sonatype.org/content/repositories/snapshots/')
@Grab('com.github.mperry:functionalgroovy-main:0.5-SNAPSHOT')
import fj.F
import fj.F2
import fj.function.Integers
@mperry
mperry / setMonadTest.groovy
Created April 14, 2014 04:08
Testing the set monad and the extension methods added from the monad combinators.
// from https://github.com/mperry/functionalgroovy/blob/master/test-extensions/src/test/groovy/com/github/mperry/fg/SetMonadExtensionTest.groovy
//@GrabResolver('https://oss.sonatype.org/content/groups/public')
@GrabResolver('https://oss.sonatype.org/content/repositories/snapshots/')
@Grab('com.github.mperry:functionalgroovy-main:0.5-SNAPSHOT')
import fj.F
import fj.F2
import fj.function.Integers
import groovy.transform.TypeChecked
@mperry
mperry / setTypeChecking.groovy
Last active August 29, 2015 13:59
Example of found defect in Groovy 2.3.0-beta-2
/**
* This scripts runs successfully with Groovy 2.2.2, but not with Groovy 2.3.0-beta-2
*/
@Grab('junit:junit:4.11')
import groovy.transform.TypeChecked
import org.junit.Test
import static org.junit.Assert.assertTrue
@Grab("org.functionaljava:functionaljava:3.1")
import fj.F
import fj.data.Stream
import groovy.transform.Memoized
@Memoized
Stream<Integer> primes() {
Stream.cons(2, { ->
Stream.range(3).filter { Integer i ->
@mperry
mperry / staticMethodTypeChecking.groovy
Last active August 29, 2015 14:00
Static methods do not type check generic parameters properly
// defect in Groovy 2.3.0-rc-1, code does not compile when it should
// run with: groovy staticMethodTypeChecking.groovy
// http://jira.codehaus.org/browse/GROOVY-6723
/*
Output is (note that line numbers will not match):
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: