{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/4085","labels_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4085/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4085/comments","events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4085/events","html_url":"https://github.com/elixir-lang/elixir/issues/4085","id":122991045,"number":4085,"title":"with .. do .. else .. end","user":{"login":"benwilson512","id":247817,"avatar_url":"https://avatars.githubusercontent.com/u/247817?v=3","gravatar_id":"","url":"https://api.github.com/users/benwilson512","html_url":"https://github.com/benwilson512","followers_url":"https://api.github.com/users/benwilson512/followers","following_url":"https://api.github.com/users/benwilson512/following{/other_user}","gists_url":"https://api.github.com/users/benwilson512/gists{/gist_id}","starred_url":"https://api.github.com/users/benwilson512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benwilson512/subscriptions","organizations_url":"https://api.github.com/users/benwilson512/orgs","repos_url":"https://api.github.com/users/benwilson512/repos","events_url":"https://api.github.com/users/benwilson512/events{/privacy}","received_events_url":"https://api.github.com/users/benwilson512/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/App:Elixir","name":"App:Elixir","color":"CCCCCC"},{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/Kind:Enhancement","name":"Kind:Enhancement","color":"009800"},{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/Level:Advanced","name":"Level:Advanced","color":"f7c6c7"},{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/Note:Discussion","name":"Note:Discussion","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-12-18T17:20:22Z","updated_at":"2015-12-24T11:29:11Z","closed_at":null,"body":"I want to look at the viability of allowing an else clause on the newly introduced `with`. Right now `with` obviously flattens the success cases of matching, but it also effectively flattens the error cases. Unfortunately there isn't a built in mechanism with `with` to take advantage of the flattened error cases. So for example a common pattern that has arisen in my code around building dependent ecto models is:\r\n\r\n```elixir\r\n  def create(params) do\r\n    with {:ok, organization} <- create_organization(params),\r\n         {:ok, address}      <- create_address(organization, params) do\r\n      {:ok, %{organization | address: address}}\r\n    end\r\n    |> case do\r\n      {:ok, organization} -> {:ok, organization}\r\n      {:error, changeset} -> {:error, changeset |> error_string}\r\n    end\r\n  end\r\n```\r\n\r\nThis could more succinctly written if `with` had an else clause\r\n\r\n```elixir\r\n  def create(params) do\r\n    with {:ok, organization} <- create_organization(params),\r\n         {:ok, address}      <- create_address(organization, params) do\r\n      {:ok, %{organization | address: address}}\r\n    else\r\n      {:error, changeset} -> {:error, changeset |> error_string}\r\n    end\r\n  end\r\n```\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/comments/167095876","html_url":"https://github.com/elixir-lang/elixir/issues/4085#issuecomment-167095876","issue_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4085","id":167095876,"user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"created_at":"2015-12-24T11:29:11Z","updated_at":"2015-12-24T11:29:11Z","body":"> offtopic: I wish Elixir supported line breaking with \\ or similar, to be able to write code like this:\r\n\r\nIt **does**. :)"}}