Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monad Comprehension with Either fails: method flatMap not found in Either$RightProjection #29

Open
LuisMuniz opened this issue Jan 7, 2016 · 0 comments

Comments

@LuisMuniz
Copy link

Hi,

Is there something missing in Either to be able to use it in your monad comprehension?

class ComprehensionSpec extends Specification {
    def "Uses fj.Either in a monad comprehension"(){
        given:
        def s=Either.right("1")
        def i=Either.right(1)

        when:
        def sum=Comprehension.foreach {
            i1 << s.right()
            i2 << i.right()
            yield {
                (i1 as Integer) + i2
            }
        }


        then:
        sum.isRight()
    }
}

In this example I get an exception:

groovy.lang.MissingMethodException: No signature of method: fj.data.Either$RightProjection.flatMap() is applicable for argument types: (com.github.mperry.fg.Comprehension$_process_closure3) values: [com.github.mperry.fg.Comprehension$_process_closure3@5830b878]
Possible solutions: flatten(), flatten(groovy.lang.Closure)

    at com.github.mperry.fg.Comprehension.process(Comprehension.groovy:66)
    at com.github.mperry.fg.Comprehension.startProcessing(Comprehension.groovy:26)
    at com.github.mperry.fg.Comprehension.yield(Comprehension.groovy:21)
    at com.b2boost.commons.monad.either.ComprehensionSpec._spock_feature_0_0_closure1(ComprehensionSpec.groovy:20)
    at com.b2boost.commons.monad.either.ComprehensionSpec._spock_feature_0_0_closure1(ComprehensionSpec.groovy)
    at com.github.mperry.fg.Comprehension.foreach(Comprehension.groovy:98)
    at com.b2boost.commons.monad.either.ComprehensionSpec.Uses fj.Either in a monad comprehension(ComprehensionSpec.groovy:17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant