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
OvermindDL1
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. ^.^
Last Post!
alisinabh
Binary pattern matching was the coolest thing i learned about Elixir.
I simply made scary binary structures FUN! ![]()
I really agree with this. You can even play with media files structures and have fun.
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









