Skip to content

Instantly share code, notes, and snippets.

View mariogarcia's full-sized avatar

Mario Garcia mariogarcia

View GitHub Profile
@mariogarcia
mariogarcia / GradleGroovyConsole
Created February 4, 2014 08:39
Launching a Groovy Console with your Gradle classpath
task(console, dependsOn: 'classes', type: JavaExec) {
main = 'groovy.ui.Console'
classpath = sourceSets.main.runtimeClasspath
}
@mariogarcia
mariogarcia / apache-vfs.groovy
Created February 6, 2014 23:29
GroovyConsole example of Apache Commons VFS
@Grapes([
@Grab(group='org.apache.commons', module='commons-vfs2', version='2.0'),
@Grab(group='commons-httpclient', module='commons-httpclient', version='3.1')
])
import org.apache.commons.vfs2.VFS
import org.apache.commons.vfs2.FileUtil
import org.apache.commons.vfs2.FileListener
import org.apache.commons.vfs2.FileObject
import org.apache.commons.vfs2.FileSystemManager
@GrabResolver(name='grails-core', root='http://repo.grails.org/grails/core')
@Grab(group='org.grails', module='grails-datastore-gorm-mongo', version='1.0.0.BUILD-SNAPSHOT')
@Grab(group='org.slf4j', module='slf4j-simple', version='1.6.1')
import grails.persistence.*
import org.grails.datastore.gorm.mongo.config.*
MongoDatastoreConfigurer.configure("myDatabase", Book)
Book.withSession {
@mariogarcia
mariogarcia / groovy_haskell_where.groovy
Last active August 29, 2015 13:58
Groovy version of the Haskell where clause
class FnCheck {
static class Evaluation {
Closure condition
Closure execution
}
def conditions = []
def parameters = [:]
import groovyx.gpars.actor.Actors
import groovyx.gpars.actor.DefaultActor
import groovyx.gpars.actor.DynamicDispatchActor
class SupervisedException extends Exception {
SupervisedException(String message) {
super(message)
}
}
@mariogarcia
mariogarcia / gist:af88669efd1057654f51
Last active August 29, 2015 14:04
Functor, Appllicative y Monad
import groovy.transform.Immutable
// PROTOCOLO
interface Functor {
Functor fmap(Closure fn)
}
interface Applicative {
Applicative fapply(Applicative afn)
@mariogarcia
mariogarcia / Something.groovy
Last active August 29, 2015 14:04
New version of categories research
interface Fn<I,O> {
O execute(I i)
}
// applies a function to a value
// TODO while I think functions could be parametrized
// functors should not. Functions are a special case
// of functors
interface Functor<I,O> {
I getValue()
@mariogarcia
mariogarcia / BusinnessValidation.groovy
Created August 25, 2014 12:22
Thinking about business validation + functional style
interface HasUser {
User getUser()
}
interface HasBank {
Bank getBank()
}
interface Validator<T> {
Boolean validate(T validateable)
@mariogarcia
mariogarcia / bind.java
Created September 12, 2014 13:32
ListMonad bind draft implementation
@Override
public <B, M extends Monad<B>> M bind(Function<A, M> fn) {
List<B> result = new ArrayList<>();
for(A v : this.getTypedRef().getValue()) {
ListMonad<B> partialMonad = (ListMonad<B>) fn.apply(v);
result.addAll(partialMonad.getTypedRef().getValue());
}
return (M) result;
}
@mariogarcia
mariogarcia / list_comprehension.groovy
Last active August 29, 2015 14:06
silly list comprehension
def elements = [1..4, 30..50, 'a'..'d']
def iterators = elements*.iterator()
while(iterators*.hasNext().every()) {
println iterators*.next()
}