com.github.mperry.fg.Generator.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalgroovy-main Show documentation
Show all versions of functionalgroovy-main Show documentation
FunctionalGroovy enhances FunctionalJava for Groovy
package com.github.mperry.fg
import fj.data.Option
import fj.data.Stream
import groovy.transform.Canonical
import groovy.transform.TypeChecked
/**
* Created with IntelliJ IDEA.
* User: MarkPerry
* Date: 25/02/13
* Time: 11:48 PM
* To change this template use File | Settings | File Templates.
*/
@Canonical
@TypeChecked
class Generator {
String name
Closure func
Boolean guard = false
static Boolean ALLOW_UKNOWN_TYPES = true
// left shift should only accept a Functor or Monad
def leftShift(final Stream s) {
func = { s }
}
def leftShift(final List list) {
func = { list }
}
def leftShift(final Collection c) {
func = { c }
}
def leftShift(final Option o) {
func = { o }
}
def leftShift(final Closure c) {
func = c
}
def leftShift(final Object o) {
if (ALLOW_UKNOWN_TYPES) {
func = { o }
} else {
throw new UnsupportedOperationException("Comprehension not supported for object $o with class ${o.class.canonicalName}")
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy