fmcgeough

fmcgeough

pipe into case? I use that fairly frequently…unless I’m misunderstanding what you’re wanting…could be.. its still very early…

str = "Hello"
str |> case do
   "Goodbye" -> "see ya!"
   "Hello" -> "welcome!"
end

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Yep this! I pipe into case statements probably a lot more excessively than I really should… ^.^;

And I pipe into if and other such things as well… >.>

jeremyjh

jeremyjh

Oh my…so much code I have to rewrite now! Wow thats something I really…should have…checked.

AstonJ

AstonJ

Cool tip - moved into a new thread :003:

joaoevangelista

joaoevangelista

OMG, just please don’t pipe when you don’t need it, I just don’t see any improvement when piping for example just one time e.g. mylist |> Enum.map(myfunc). It is such less readable, just because you can, it doesn’t mean you should :wink:

yawaramin

yawaramin

Yup!

One pipe–not worth it.

Two or more pipes–extremely worth it :slight_smile:

sztosz

sztosz

I always find this something |> IO.inspect() more readable than IO.inspect(something) I really don’t see nothing wrong with piping even when there is only one pipe

If you do

something 
|> do_something()
|> do_something_else()
|> with_additional_param(param)

then what’s wrong with just

something |> do_something()

I think we should not mistake readability with familiarity. Just my 2 cents.

joaoevangelista

joaoevangelista

Yet in the end it is just personal taste I think. for people’s doing elixir It is pretty normal, new devs coming to the code base might not get over it easily. I just think that reading this piped into IO.inspect is less readable than IO.inspect this because it looks more like a description of a command. And reaching for | and > is hard :laughing:

dbern

dbern

Piping into case is pretty cool, but after I do it, I realize it’s often better for me to wrap that case statement into a function that I can name so it reveals the intention a little better.

I especially don’t like doing it in the middle of a pipeline. I find myself using case statements more often in Phoenix controllers to handle the happy path and unhappy path.

NobbZ

NobbZ

This style often confused subject and object. Therefore I’m not really a friend of it.

joaoevangelista

joaoevangelista

Also a fan of that, and we can use pattern matching in the head of the function as each case match, since both will be compiled down to the same thing

Where Next? Top

Trending in Guides/Tuts Top

c4lliope
# ~/src/livebook/.iex.exs System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] ) Because Livebook requires a unique passcode on ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews