
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

Classroom-tested by tens of thousands of students, this new edition of the bestselling intro to programming book is for anyone who wants ...
New

Ruby, Io, Prolog, Scala, Erlang, Clojure, Haskell. With Seven Languages in Seven Weeks, by Bruce A. Tate, you’ll go beyond the syntax—and...
New

Currently a hot topic in the BEAM world, let’s start a thread for it (as suggested by @crowdhailer here) :smiley:
What are your current...
New

Kotlin v1.4.0 has been released.
Link: Release Kotlin 1.4.0 · JetBrains/kotlin · GitHub
New

Hi this week it’s Code Mesh V when London’s leading alternative tech conference goes virtual for the first time. Talks are set for both U...
New

Ruby on Rails v6.1.0 has been released.
Link: Release 6.1.0 · rails/rails · GitHub
New

Hey everybody!
I’m working on the project that includes import of Oracle data to PostgreSQL. That data comes as Oracle export (expdp) fi...
New

Reading Programming Elixir 1.6 book, I’ve completed part 1 of the book. Now I’m thinking of reading Elixir in Action. What do you all sug...
New

Woooooooo! This is such a huge release for it, and 2 years incoming!
In short, the library is now using an updated hyper backend (not j...
New

Hello folks! We had a pretty fun thread here around the same time last year - talking about Advent of Code problems. That also happened t...
New
Other popular topics

What chair do you have while working… and why?
Is there a ‘best’ type of chair or working position for developers?
New

I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New

Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face:
Perhaps if there’s enough peop...
New

poll
poll
Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New

Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face:
https://on...
New

This looks like a stunning keycap set :orange_heart:
A LEGENDARY KEYBOARD LIVES ON
When you bought an Apple Macintosh computer in the e...
New

A Hero’s Journey
with Chris Pine
@chrispine
Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New

Woooooooo! This is such a huge release for it, and 2 years incoming!
In short, the library is now using an updated hyper backend (not j...
New

Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry:
He left this note on Twitter on the weekend:
And one...
New

Author Spotlight:
Sophie DeBenedetto
@SophieDeBenedetto
The days of the traditional request-response web application are long gone, b...
New
Latest in Backend
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /sublime-text
- /textmate
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /c
- /julia
- /slackware
- /neovim