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
                        
                      
                      
                I dabbled in Phoenix for a while now, but never really got my hands dirty with it right up until now. Apart from the whole framework bein...
              
            
            
              
          
              New
                Understanding Partial Moves in Rust. 
Partial moves are an interesting but often misunderstood feature of Rust.  However, with the right ...
              
            
            
              
          
              New
                It’s not legacy code — it’s PHP. 
Vimeo has been using PHP in production for over 15 years. Find out how we keep a million lines of PHP i...
              
            
            
              
          
              New
                When I need to configure something in a complicated way, I find myself reviewing the embedded language that provided the server to create...
              
            
            
              
          
              New
                The perspective of an ignorant computer science undergrad
It’s likely that you read the title of this post and thought “what is this guy ...
              
            
            
              
          
              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
                There is a new community resource available on writing “Safe Ecto Migrations”. When we get a migration wrong, it can lock up your product...
              
            
            
              
          
              New
                Another week, another oldies-but-goldies post… 
This one about Test Driven Development.
              
            
            
              
          
              New
                Ruby’s Struct is one of several powerful core classes which is often overlooked and under utilized compared to the more popular Hash clas...
              
            
            
              
          
              New
                As DoorDash transitioned from Python monolith to Kotlin microservices, our engineering team was presented with a lot of opportunities to ...
              
            
            
              
          
              New
Other popular topics
                        
                      
                      
                I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
              
            
            
          
              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
                Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
              
            
            
              
          
              New
                Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
              
            
            
              
          
              New
                Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
              
            
            
          
              New
                Biggest jackpot ever apparently! :upside_down_face: 
I don’t (usually) gamble/play the lottery, but working on a program to predict the...
              
            
            
          
              New
                Was just curious to see if any were around, found this one: 
I got 51/100: 
  
Not sure if it was meant to buy I am sure at times the b...
              
            
            
          
              New
                Author Spotlight 
Erin Dees 
@undees 
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
              
            
            
          
              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
                Hello, 
I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
              
            
            
          
              New
Latest in Elixir
Latest in Phoenix
Categories:
Sub Categories:
Popular Portals
- /elixir
 - /rust
 - /ruby
 - /wasm
 - /erlang
 - /phoenix
 - /keyboards
 - /python
 - /rails
 - /js
 - /security
 - /go
 - /swift
 - /vim
 - /clojure
 - /emacs
 - /haskell
 - /java
 - /svelte
 - /onivim
 - /typescript
 - /kotlin
 - /c-plus-plus
 - /crystal
 - /tailwind
 - /react
 - /gleam
 - /ocaml
 - /flutter
 - /elm
 - /vscode
 - /ash
 - /opensuse
 - /html
 - /centos
 - /php
 - /zig
 - /deepseek
 - /scala
 - /sublime-text
 - /lisp
 - /textmate
 - /react-native
 - /nixos
 - /debian
 - /agda
 - /kubuntu
 - /arch-linux
 - /django
 - /deno
 - /revery
 - /ubuntu
 - /spring
 - /nodejs
 - /manjaro
 - /diversity
 - /lua
 - /julia
 - /c
 - /slackware
 

    




