Skip to content

enumerable methods not correctly iterating over an enumerable #16

@HoneyryderChuck

Description

@HoneyryderChuck

I'm finding this behaviour non-intuitive in terms of applying the monad on enumerable objects, like arrays. For instance, here we have the example from the tutorial:

Maybe([nil, 1, 2, 3, 4, 5, 6].sample)
#=> <Some:0x007ffe198e6128 @value="I'M A VALUE">

when we do:

Maybe([nil, 1, 2, 3, 4, 5, 6])
#=> <Some:0x007ffe198e6128 @value="[nil, 1, 2, 3, 4, 5, 6]">

this is where I get confused. I'll show you my expectation and what it does:

Maybe([nil, 1, 2, 3]).reduce(0, :+)
#=> expecting 6, throws TypeError:Array can't be coerced into Fixnum

So, my expecting in this case, when using enumerable method on the monad, was that the monad would yield monads, which is not. Is this a valid expectation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions