{"action":"created","issue":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/300","labels_url":"https://api.github.com/repos/javaslang/javaslang/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/300/comments","events_url":"https://api.github.com/repos/javaslang/javaslang/issues/300/events","html_url":"https://github.com/javaslang/javaslang/issues/300","id":89297365,"number":300,"title":"[Analysis] How to add a Monad abstraction on top of existing monadic classes.","user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/javaslang/javaslang/labels/feature","name":"feature","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/javaslang/javaslang/milestones/17","html_url":"https://github.com/javaslang/javaslang/milestones/2.1.0","labels_url":"https://api.github.com/repos/javaslang/javaslang/milestones/17/labels","id":1081169,"number":17,"title":"2.1.0","description":"Async Streaming IO","creator":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":0,"state":"open","created_at":"2015-04-23T20:05:59Z","updated_at":"2015-06-23T21:43:38Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-06-18T13:40:47Z","updated_at":"2015-07-04T15:16:25Z","closed_at":null,"body":"Here is a Scala example, taken from @travisbrown's [abstracted](https://github.com/travisbrown/abstracted). We need to check what is possible with Java in this direction.\r\n\r\nDue to the lack of higher-kinded types, clearly Java's type system is not powerful enough to express this. The intention of this analysis story is, to investigate if we are able to create a Monad abstraction on top of existing classes without modifying them.\r\n\r\n```scala\r\ncase class Box[A](val a: A) {\r\n  def map[B](f: A => B): Box[B] = {\r\n    println(\"Box's map\")\r\n    Box(f(a))\r\n  }\r\n\r\n  def flatMap[B](f: A => Box[B]): Box[B] = {\r\n    println(\"Box's flatMap\")\r\n    f(a)\r\n  }\r\n}\r\n```\r\n\r\nAnd a monad instance for it:\r\n\r\n```scala\r\nimport cats.Monad\r\n\r\nimplicit val boxMonad: Monad[Box] = new Monad[Box] {\r\n  override def map[A, B](fa: Box[A])(f: A => B): Box[B] = {\r\n    println(\"Box's functor's map\")\r\n    Box(f(fa.a))\r\n  }\r\n\r\n  def flatMap[A, B](fa: Box[A])(f: A => Box[B]): Box[B] = {\r\n    println(\"Box's monad's flatMap\")\r\n    f(fa.a)\r\n  }\r\n\r\n  def pure[A](a: A): Box[A] = Box(a)\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/comments/118520436","html_url":"https://github.com/javaslang/javaslang/issues/300#issuecomment-118520436","issue_url":"https://api.github.com/repos/javaslang/javaslang/issues/300","id":118520436,"user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"created_at":"2015-07-04T15:16:25Z","updated_at":"2015-07-04T15:16:25Z","body":"@johnmcclean-aol Awesome, thanks for doing all the work. I will check it out."}}