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
Understanding Partial Moves in Rust.
Partial moves are an interesting but often misunderstood feature of Rust. However, with the right ...
New
So you’re enjoying using WebSockets with Elixir’s Phoenix Framework, and you want to send some binary messages. Maybe it’s an audio clip,...
New
Once a year, I look back at the recent developments in the PHP world, and also look forward to what’s to come. And just like in 2020 and ...
New
This post is a spiritual successor to Loris Cro’s Go cross-compilation.
The encounter
During a recent stage 2 meeting Jakub Konka wanted...
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
In episode 78 of Thinking Elixir, we talk with Chase Granberry about Logflare. We learn why Chase started the company, what Logflare does...
New
In this blog post over on Fly.io I take a look at PHP 8.1’s new Enum class, and show you how it can be used to set up a level structure f...
New
In a 2 day spike, I created my own Elixir-based AI Personal Fitness Trainer! The surprising part for me was how useful and helpful I foun...
New
Peeper is the tiny library to preserve state across GenServer crashes/restarts.
Works as an almost drop-in substitute for GenServer, sui...
New
Learn how set up an RTMP server for free using the open-source Red5 software. This tutorial covers all steps from downloading the code fr...
New
Other popular topics
Free and open source software is the default choice for the technologies that run our world, and it’s built and maintained by people like...
New
What chair do you have while working… and why?
Is there a ‘best’ type of chair or working position for developers?
New
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
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
Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
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
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
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
Get the comprehensive, insider information you need for Rails 8 with the new edition of this award-winning classic.
Sam Ruby @rubys
...
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
- /flutter
- /elm
- /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
- /manjaro
- /spring
- /diversity
- /lua
- /julia
- /markdown
- /c








