ehayun

ehayun

I have 2 arrays: a1 can be any combination of value or nil like that

a1 = [1,nil,3]

and array 2 the same

a2 = [4,2, nil]

How do I combine them together in a way that if a2 contains a value its value will take
so, in the above array the result will be: [4,2,3]

Showing Posts 1 to 2

NobbZ

NobbZ

  1. There are no arrays in Elixir.

  2. You can probably use Enum.zip_with/2. The following should do if I understand you correctly (a2 takes precedennce unless it is nil):

    Enum.zip_with([a1, a2], fn [a, nil] -> a; [_, b] -> b end)
    
ehayun

ehayun OP

OK, list, not array :slight_smile:
thanks for your answer

— All posts loaded —

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews