Fl4m3Ph03n1x

Fl4m3Ph03n1x

Make `mix format` work with pipeline macros

Background

I use a library that defines a new pipeline macro, the triple arrow >>>. So in my code, it is normal to have something like this:

def safe_div(a, b), do:
  a 
  |> divide(b)
  >>> handle_result()

This magic here is in handle_result. What the >>> does is not important, what matters here is that this is a type of format that I want to see in my code.

Problem

The problem here is the mix format does not know how that it should treat >>> as it treats |>. So inevitably my code becomes:

def safe_div(a, b), do:
  a 
  |> divide(b) >>> handle_result()

Which is very ugly and impossible to read for larger functions.

I have tried to find a way to change mix format’s configuration to fix this issue, unfortunately I was not able to find anything.

Question

  • Can I configure mix format to treat >>> as a |> ?
  • If not, would it be a bad idea to make a PR where people would be allowed to define “pipelike” operators/macros, thus telling mix format how to behave?

Basically, what options do I have here ?

Marked As Solved

josevalim

josevalim

Creator of Elixir

Here are the operators we consider pipeline like: elixir/lib/elixir/lib/code/formatter.ex at v1.11.4 · elixir-lang/elixir · GitHub

>>> isn’t one because it is also used as a Bitwise operator by Elixir.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement