• Stars
    star
    67
  • Rank 462,689 (Top 10 %)
  • Language
    Groovy
  • Created almost 12 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Functional programming in Groovy

Functional Groovy

Functional Groovy is a library for doing functional programming (FP) in Groovy. It is a Groovy extension module for Functional Java (FJ), adding Groovy idioms and new FP constructs in Groovy.

Features includes:

  • FunctionalJava based
  • Enhances FunctionalJava for Groovy as a Groovy extension module
  • Groovy Quickcheck style property testing (specification based testing)
  • Monad library using a minimal monad implementation (unit/flatMap)
  • Monadic functions added to the standard Java List
  • Monad comprehensions (dynamically typed)
  • Lenses
  • Reader, Writer and State monads
  • A simple IO type
  • Y Combinator

The project has some cloud build servers I used to experiment with including:

I have written an initial blog post on Groovy Null Handling using Bind, Comprehensions and Lift covering:

  • some introductory material on functional programming in Groovy
  • how to begin using the Functional Groovy library
  • handling nulls by binding through the Option type, monadic comprehensions and monadic lifting

The full list of related posts are:

To start using the library add the dependency com.github.mperry:functionalgroovy-main:0.5.1-SNAPSHOT to your Gradle project. A simple test script to get going (test.groovy) is:

@GrabResolver('https://oss.sonatype.org/content/groups/public')
@Grab('com.github.mperry:functionalgroovy-core:0.5.1-SNAPSHOT')
@Grab('org.functionaljava:functionaljava:4.1')

import com.github.mperry.fg.*

1.to(5).each {
    println it
}

Run this script using groovy test.groovy.

This project uses:

  • JDK 8
  • Gradle 1.11
  • Groovy 2.3.2
  • Functional Java 4.1
  • Intellij Community Edition 13.1

I have added a list of open issues so feel free to contribute. Some ways of contributing are:

  • adding new functionality
  • adding tests
  • adding FP in Groovy examples
  • adding FunctionalGroovy usage examples

Functional Groovy is divided into four components: core, main, demo, java8 and consume.

  • Core enhances Functional Java with Groovy idioms
  • Main adds new functionality
  • Demo includes examples of FP in Groovy and usage of this library
  • Java8 includes enhancements related to Java 8 types (e.g. Optional).
  • Consume shows how to include FunctionalGroovy in your project