{"action":"opened","issue":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/241","labels_url":"https://api.github.com/repos/javaslang/javaslang/issues/241/labels{/name}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/241/comments","events_url":"https://api.github.com/repos/javaslang/javaslang/issues/241/events","html_url":"https://github.com/javaslang/javaslang/issues/241","id":77067520,"number":241,"title":"Reincarnate flatten() as static method","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/18","html_url":"https://github.com/javaslang/javaslang/milestones/1.2.3","labels_url":"https://api.github.com/repos/javaslang/javaslang/milestones/18/labels","id":1091674,"number":18,"title":"1.2.3","description":"","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":20,"closed_issues":8,"state":"open","created_at":"2015-04-30T20:29:59Z","updated_at":"2015-05-16T15:50:27Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-05-16T15:50:27Z","updated_at":"2015-05-16T15:50:27Z","closed_at":null,"body":"The following allows to `flatten()` Monads using a fluent API while being type safe!\r\n\r\n```java\r\ninterface Monad<T, M extends HigherKinded<?, M>> extends HigherKinded<T, M> {\r\n\r\n    <U> Monad<U, M> flatMap(Function<? super T, ? extends HigherKinded<U, M>> mapper);\r\n\r\n    static <T, TYPE extends Monad<?, TYPE>, SELF extends Monad<? extends HigherKinded<T, TYPE>, TYPE>> Monad<T, TYPE> flatten(SELF monad) {\r\n        return monad.flatMap(Function.identity());\r\n    }\r\n}\r\n\r\ninterface List<T> extends Seq<T, List<?>>, Monad<T, List<?>>, HigherKinded<T, List<?>> {\r\n\r\n    @Override\r\n    <U> List<U> flatMap(Function<? super T, ? extends HigherKinded<U, List<?>>> mapper);\r\n\r\n    <U> List<U> transform(Function<List<T>, U> f);\r\n\r\n    static <T, TYPE extends List<?>, SELF extends List<? extends List<T>>> List<T> flatten(SELF monad) {\r\n        return monad.flatMap(Function.identity());\r\n    }\r\n}\r\n```\r\n\r\nthen the following is possible:\r\n\r\n```java\r\nfinal List<Integer> list = List.of(1, 2, 3);\r\n\r\n// does not compile, which is correct!\r\nlist.transform(List::flatten);\r\n\r\n\r\nfinal List<List<Integer>> list2 = List.of(List.of(1, 2, 3));\r\n\r\nfinal Monad<Integer, List<?>> flatten = Monad.flatten(list2);\r\n\r\nfinal List<Monad<Integer, List<?>>> transform = list2.transform(Monad::flatten);\r\n\r\nfinal List<List<Integer>> transform1 = list2.transform(List::flatten);\r\n```\r\n\r\nw00t!"}}