Creating a monad for repeated methods

I am trying to figure out which monads are in Scala.

Let's say, for example, I have methods in Java:

public void doSomeThing()

public void doOtherThing()

public void doSomeOtherThing()


All methods starting with do

, just call the method call with the name call

. If I convert this to a generic method in Java like:

public void doGeneric(SomeClass a)


and say it as a generic method, with a function call

, then doGeneric

is it a monad? Correct me if I am wrong.

Please note that I have provided examples in Java since I am just getting started with Scala.


source to share

1 answer

The monad is associated with the concept of "container", for example Option

or List

Basically, the container that defines a method flatMap

is a monad:

trait Monad[A] { //let say a Monad container to be general. A well-known would be Option
  def flatMap[B](f: A => Monad[B]): Monad[B]


In your case, you are just calling a method on one object.
You are not calculating the value "container" from another container, so you don't have a monad.
Indeed, you are just using polymorphism.



All Articles