alisinabh
Best way to achieve empty string
So in elixir sometimes you need to do something like this:
def function(acc, condition1, condition2) do
acc <>
cond do
condition1 -> "hello"
condition2 -> "world!"
true -> "" # Add nothing to acc
end
end
Sometimes you need to use an empty string. Currently i only see two options for that
- using
""(empty string with two double qoutes) - using
<<>>(empty binary)
It would be a good thing if Elixir’s String module would provide a function like: String.empty/0 that would return a human readable form of empty string in Elixir.
But for now, Which way you think is better to use? 1 or 2? Or any other solutions?
I personally think that 2 is better since no special chars can hide inside it!
Most Liked
rvirding
Have you never used binaries for protocols? ![]()
OvermindDL1
Heh, now that Unicode is out in full force, that is not at all a bad point, hmm…
OvermindDL1
Network protocols! Bitstring syntax in network protocols in Erlang is an utter bliss compared to any other language I’ve used! ^.^
Like parse out the TCPv4 packet format from scratch, just for fun, then try it in any other language. ^.^
Popular in Questions
Other popular topics
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








