cgrothaus
3 different ways to build a list with conditional elements in Elixir (and what that has to do with application startup)
I wrote a blog post about 3 different ways to build a list with conditional elements in Elixir (and what that has to do with application startup).
Most Liked
Eiji
There are other ways to achieve such results for example using recursive functions.
defmodule Example do
def sample(list) do
List.foldr(list, [], fn
{false, _child_spec}, acc -> acc
{true, child_spec}, acc -> [child_spec | acc]
child_spec, acc -> [child_spec | acc]
end)
end
def sample2([]), do: []
def sample2([{false, _child_spec} | rest]), do: sample2(rest)
def sample2([{true, child_spec} | rest]), do: sample2([child_spec | rest])
def sample2([child_spec | rest]), do: [child_spec | sample2(rest)]
end
input = [:not_tuple, {false, :skip_me}, {true, :no_skip}]
Example.sample(input)
Example.sample2(input)
Helpful resources:
2
Popular Backend topics
Rust vs Go — Bitfield Consulting.
Which is better, Rust or Go? Which language should you choose for your next project, and why? How do t...
New
It’s easy to view yourself as “not a real programmer.” There are programs out there that everyone uses, and it’s easy to put their develo...
New
Post on using UDP multicasting with Elixir to broadcast presence, and listen for peers, on a local network. I have found this approach us...
New
The run-time speed and memory usage of programs written in Rust should about the same as of programs written in C, but overall programmin...
New
Summary: I describe a simple interview problem (counting frequencies of unique words), solve it in various languages, and compare perform...
New
This post explains why Scala projects are difficult to maintain.
Scala is a powerful programming language that can make certain small te...
New
I don’t like reading thick O’Reilly books when I start learning new programming languages. Rather, I like starting by writing small and d...
New
PHP 8.1 is already taking shape quite well, yet there’s one feature I’d love to see added, that’s still being discussed: multi-line short...
New
Too long have we hustled to deploy Clojure websites. Too long have we spun up one server instance per site. Too long have reminisced abou...
New
Mark Hoffman, the author of Programming WebAssembly in Rust, is a pretty hilarious lecturer if you like a dry sense of humor.
New
Other popular topics
Learn from the award-winning programming series that inspired the Elixir language, and go on a step-by-step journey through the most impo...
New
New
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
Create efficient, elegant software tests in pytest, Python's most powerful testing framework.
Brian Okken @brianokken
Edited by Kat...
New
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
Author Spotlight:
VM Brasseur
@vmbrasseur
We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig.
General-purpose programming language and toolchain for maintaini...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /centos
- /deepseek
- /php
- /scala
- /react-native
- /lisp
- /textmate
- /sublime-text
- /nixos
- /debian
- /agda
- /django
- /kubuntu
- /deno
- /arch-linux
- /nodejs
- /ubuntu
- /revery
- /spring
- /manjaro
- /lua
- /diversity
- /julia
- /markdown
- /c








