kepik919
How to call "case/cond" over String.starts_with?(a)?
I want to call a normal function and do a pattern matching over it, such as:
res = String.starts_with?(a)
case res do
"a" -> # ....
"b" -> # ....
"c" -> # ....
"d" -> # ....
_ -> # .......
end
But this thing isn’t supported in Ellixir, is it? What’be be an alternative then?
Most Liked
NobbZ
For this particular use case you can use regular pattern matching:
case a do
"a" <> _ -> # ...
end
5
hauleth
It is possible, just you use that function wrongly:
res = String.starts_with?(str, prefix)
case res do
true -> # …
false -> # …
end
4
APB9785
Creator of ECSx
It looks like you want String.first/1:
case String.first(input) do
"a" -> # ....
"b" -> # ....
"c" -> # ....
"d" -> # ....
nil -> # input was an empty string
end
This type of case matching is totally acceptable (but hopefully you won’t make 27 different clauses for it!)
3
Popular in Discussions
Hello everyone,
I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in.
phx.gen...
New
I have a sample string
sentence = "Hello, world ... 123 *** ^%&*())^% %%:>"
From this string, I want to only keep the integers, ...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Hey everyone,
this has been brewing in my head some time and it came up again while reading Adopting Elixir.
GenServers, supervisors et...
New
Another point that Dave drives home in his course is that applications really are components, and you should treat them as such. Not as “...
New
I suppose this question is effectively hackney vs. ibrowse but we are at a point in our project where we have to make a choice between th...
New
I would like to spark a discussion about the static access operator: ..
For whom does not know: it is used in Elixir to access fields of...
New
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New
Other popular topics
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
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
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









