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/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

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 th...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
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 th...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
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