owaisqayum
Hi,
I am having a list of tuples
list = [{-1, 3}, {1, 5}, {10, 15}]
When i pass it through Enum.scan, it gives me the following result. Its a program i saw on codewars but i really dont understand how the Enum.scan is working over here.
Enum.scan(list, fn {b, e}, {_, x} -> {max(b, x), max(e, x)} end)
output: [{-1, 3}, {3, 5}, {10, 15}]
I tried IO.inspect to look at the results but still, it doesn’t make any sense. Here is the result of IO.inspect
b: 1
x1: 3
max(b, x): 3
e: 5
x2: 3
max(e, x): 5
b: 10
x1: 5
max(b, x): 10
e: 15
x2: 5
max(e, x): 15
[{-1, 3}, {3, 5}, {10, 15}]
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
I’m posting this in response to Jose’s recent tweet (Cr. link) :
People are sleeping on Elixir for a coding harness:
Hot-code swappi...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes.
We’re a small ...
New
Other Trending Topics
Sept 10-11, live from Chicago. Can’t make the trip? Grab a virtual pass and stream the whole thing from wherever you are.
You get every ...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










First Post!- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
fuelen
Hi,
As you don’t pass initial accumulator, then the first element of the list was taken and the first element on output will be the same as on input -
It makes sense
{-1, 3}.Then, on first iteration
bandeare from the second element of the list andxis from accumulator which is the first element of the list.Then you build new two-element tuple which is
{3, 5}, it is used as second value in output list and as accumulator for the next element.Then on the next iteration
bandeare from the last element andxis from accumulator. Newly built tuple is{10, 15}, it is used as third element.So, we have
Maybe, it would be easier for you if we reimplement
Enum.scanusingEnum.map_reduce: