Qqwy

Qqwy

TypeCheck Core Team

Elixirs Enumerable protocol is built upon the implementation of reduce for different kinds of data structures.

Today, I had a discussion with @benwilson512, di4na and @martin in Slack, about what would be possible if map was used as building block instead.

Basically, there are things that you cannot do with just map, and things you cannot do with just reduce. You can build a semi-working map on top of reduce, but this will not work in the following circumstances:

  • Concurrent access to elements. (see for instance conc lists)
  • Changing values inside complex trees without modifying the tree shape. (AFAIK there is no way for reduce to know the shape of the container it is working on)
    (there is possibly more; let us know)

As a side note, the current reduce algorithm and most of the other functions in Enum that use it internally always return the result as a list.

Of course, there are some things that are reducable but not mappable, such as Ranges.

There are other things that are mappable, but not reducable, such as for instance a ‘Maybe’ (that is either Some x or Nothing).

I think it is interesting to brainstorm about this; Maybe the addition of a Mappable protocol isn’t such a weird idea…

Where Next? Top

Trending in Discussions Top

AstonJ
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...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews