# \#enumerables

**URL:** https://forum.elixirforum.com/tag/enumerables/67.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [Composable SFTP Streams](https://forum.elixirforum.com/t/composable-sftp-streams/75138)

<div class="topic-metadata">

**Author:** [@kevinschweikert](https://forum.elixirforum.com/u/kevinschweikert)\
**Replies:** 1\
**Last updated:** [April 27, 2026, 11:11am UTC](https://forum.elixirforum.com/t/composable-sftp-streams/75138 "2026-04-27T11:11:54Z")

</div>

I have written about something i implemented at work. It’s a nice show off for Elixir streams and protocols and the nice abstraction they provide. We learn how to wrap the Erlang/OTP :ssh\_sftp API in a Stream and imlem…

---

## [Stream.peek, Stream.pop](https://forum.elixirforum.com/t/stream-peek-stream-pop/73993)

<div class="topic-metadata">

**Author:** [@Asd](https://forum.elixirforum.com/u/Asd)\
**Replies:** 2\
**Last updated:** [January 17, 2026, 12:47am UTC](https://forum.elixirforum.com/t/stream-peek-stream-pop/73993 "2026-01-17T00:47:02Z")

</div>

Stream.peek and Stream.pop I find Stream API limited and I often have to introduce workarounds for things like taking values from enumerable one by one without traversing the whole enumerable at one go. To achieve this …

---

## [How to define the type of a Stream with a specific type of elements?](https://forum.elixirforum.com/t/how-to-define-the-type-of-a-stream-with-a-specific-type-of-elements/71630)

<div class="topic-metadata">

**Author:** [@bvobart](https://forum.elixirforum.com/u/bvobart)\
**Replies:** 4\
**Last updated:** [July 9, 2025, 3:47pm UTC](https://forum.elixirforum.com/t/how-to-define-the-type-of-a-stream-with-a-specific-type-of-elements/71630 "2025-07-09T15:47:30Z")

</div>

For a list of integers, I can simply write a typespec like this: @type foo() :: \[integer()\] # or list(integer()) But what about a Stream of integers? There is no Stream.t() or Stream.t(element\_type) and Enum.t() does …

---

## [Guard test for protocol?](https://forum.elixirforum.com/t/guard-test-for-protocol/70794)

<div class="topic-metadata">

**Author:** [@heilong](https://forum.elixirforum.com/u/heilong)\
**Replies:** 1\
**Last updated:** [May 9, 2025, 8:01am UTC](https://forum.elixirforum.com/t/guard-test-for-protocol/70794 "2025-05-09T08:01:17Z")

</div>

Is there a guard for testing protocol implementation? is\_proto/2 For example, how to guard test for implementing Enumerable? I understand some will say it’s not necessary, because the execution will fail at the first …

---

## [Enum.reduce/3 vs Enumerable.reduce/3](https://forum.elixirforum.com/t/enum-reduce-3-vs-enumerable-reduce-3/69268)

<div class="topic-metadata">

**Author:** [@James\_E](https://forum.elixirforum.com/u/James_E)\
**Replies:** 15\
**Last updated:** [February 7, 2025, 1:10pm UTC](https://forum.elixirforum.com/t/enum-reduce-3-vs-enumerable-reduce-3/69268 "2025-02-07T13:10:30Z")

</div>

How would you leverage or translate an existing, clear Enum.reduce/3-alike struct method into a valid defimpl for Enumerable.reduce/3? When implementing a “simple” reducer, it’s clear enough (at least how to map the cal…

---

## [Arrays - Fast and versatile arrays with swappable implementations](https://forum.elixirforum.com/t/arrays-fast-and-versatile-arrays-with-swappable-implementations/42146)

<div class="topic-metadata">

**Author:** [@Qqwy](https://forum.elixirforum.com/u/Qqwy)\
**Replies:** 14\
**Last updated:** [July 19, 2024, 11:59am UTC](https://forum.elixirforum.com/t/arrays-fast-and-versatile-arrays-with-swappable-implementations/42146 "2024-07-19T11:59:38Z")

</div>

While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Elixir for certain situations. However, so far a stable and idiomatic array library wa…

---

## [Filter list of maps](https://forum.elixirforum.com/t/filter-list-of-maps/17054)

<div class="topic-metadata">

**Author:** [@michaelb](https://forum.elixirforum.com/u/michaelb)\
**Replies:** 5\
**Last updated:** [June 3, 2024, 2:52am UTC](https://forum.elixirforum.com/t/filter-list-of-maps/17054 "2024-06-03T02:52:29Z")

</div>

Hello! I’m trying to filter list of maps to remove items where value of key was declared previously in this list. List that I have: list = \[%{ "distance" =\> "4", "source" =\> "source\_1", }, %{ "distance" =\> …

---

## [How to filter a list of maps by multi keys?](https://forum.elixirforum.com/t/how-to-filter-a-list-of-maps-by-multi-keys/63757)

<div class="topic-metadata">

**Author:** [@formingform](https://forum.elixirforum.com/u/formingform)\
**Replies:** 4\
**Last updated:** [May 28, 2024, 1:55am UTC](https://forum.elixirforum.com/t/how-to-filter-a-list-of-maps-by-multi-keys/63757 "2024-05-28T01:55:29Z")

</div>

Hello! I’m trying to filter list of maps to remove items where value of key was declared previously in this list. List that I have: list = \[ %{name: "01", type: "t\_01", desc: "desc\_01\_1"}, %{name: "02", type: "t\_02…

---

## [Trouble understanding octet string (binary) iteration](https://forum.elixirforum.com/t/trouble-understanding-octet-string-binary-iteration/62304)

<div class="topic-metadata">

**Author:** [@James\_E](https://forum.elixirforum.com/u/James_E)\
**Replies:** 6\
**Last updated:** [March 14, 2024, 8:12pm UTC](https://forum.elixirforum.com/t/trouble-understanding-octet-string-binary-iteration/62304 "2024-03-14T20:12:24Z")

</div>

The Comprehensions article says: In Elixir, it is common to loop over an Enumerable … Comprehensions are syntactic sugar for such constructs However, this simple example of Enumerable manipulation: # \[11, 22, 33\] \[1…

---

## [How to remove duplication from typespec and static list of values?](https://forum.elixirforum.com/t/how-to-remove-duplication-from-typespec-and-static-list-of-values/62252)

<div class="topic-metadata">

**Author:** [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Replies:** 1\
**Last updated:** [March 12, 2024, 3:23pm UTC](https://forum.elixirforum.com/t/how-to-remove-duplication-from-typespec-and-static-list-of-values/62252 "2024-03-12T15:23:15Z")

</div>

Background I have a structure where the new function requires a parameter to be part of a closed set of values (think of it as an enum). So what I am doing is that I am basically duplicating them in the following way: d…

---

## [Recursion using only original list](https://forum.elixirforum.com/t/recursion-using-only-original-list/56719)

<div class="topic-metadata">

**Author:** [@bendevski](https://forum.elixirforum.com/u/bendevski)\
**Replies:** 3\
**Last updated:** [June 27, 2023, 11:41am UTC](https://forum.elixirforum.com/t/recursion-using-only-original-list/56719 "2023-06-27T11:41:17Z")

</div>

I’m playing around with elixir and solving some leetcode problems but I ran into an issue. The following code: defmodule Solution do @spec climb\_stairs(n :: integer) :: integer def climb\_stairs(n) do climb\_stair…

---

## [Enum fusion?](https://forum.elixirforum.com/t/enum-fusion/36193)

<div class="topic-metadata">

**Author:** [@Qqwy](https://forum.elixirforum.com/u/Qqwy)\
**Replies:** 43\
**Last updated:** [January 10, 2023, 5:53pm UTC](https://forum.elixirforum.com/t/enum-fusion/36193 "2023-01-10T17:53:37Z")

</div>

Hi all! As you may know, it is very common in idiomatic Elixir code to work with transformations on datastructures, especially those implementing the Enumerable protocol. Usually we use the functions from Enum (and some…

---

## [Different behavior between List.flatten() and Enum/Stream.flat\_map()](https://forum.elixirforum.com/t/different-behavior-between-list-flatten-and-enum-stream-flat-map/52826)

<div class="topic-metadata">

**Author:** [@pertsevds](https://forum.elixirforum.com/u/pertsevds)\
**Replies:** 11\
**Last updated:** [December 30, 2022, 2:52pm UTC](https://forum.elixirforum.com/t/different-behavior-between-list-flatten-and-enum-stream-flat-map/52826 "2022-12-30T14:52:11Z")

</div>

When i use List.flatten() it would flatten a deep list with every nested . iex\> list = \[\[\],\["ant",\["hello","hi",\[\[\[\]\]\]\], "bat"\], \["cat", "dog"\]\] \[\[\], \["ant", \["hello", "hi", \[\[\[\]\]\]\], "bat"\], \["cat", "dog"\]\] iex\> List.fl…

---

## [How to generate permutations from different sets of elements?](https://forum.elixirforum.com/t/how-to-generate-permutations-from-different-sets-of-elements/51003)

<div class="topic-metadata">

**Author:** [@heves](https://forum.elixirforum.com/u/heves)\
**Replies:** 12\
**Last updated:** [October 14, 2022, 2:35pm UTC](https://forum.elixirforum.com/t/how-to-generate-permutations-from-different-sets-of-elements/51003 "2022-10-14T14:35:41Z")

</div>

I’d like to generate a list from a variable length list of lists, choosing one element from each one. Like this: list = \[\[:a, :b\], \[1, 2, 3\], \[{4, 5}, {5, 6}\]\] magic\_function(list) Output: \[:a, 1, {4, 5}\] \[:a, 1, {5, …

---

## [Enumerable not implemented for nil of type Atom](https://forum.elixirforum.com/t/enumerable-not-implemented-for-nil-of-type-atom/46905)

<div class="topic-metadata">

**Author:** [@docjazither](https://forum.elixirforum.com/u/docjazither)\
**Replies:** 4\
**Last updated:** [March 31, 2022, 1:44pm UTC](https://forum.elixirforum.com/t/enumerable-not-implemented-for-nil-of-type-atom/46905 "2022-03-31T13:44:30Z")

</div>

G’day OGs I have this code as follows: def create(conn, %{"a" =\> a\_params}) do with true \<- someClause(), a\_params \<- someClause(a\_params), :ok \<- Enum.reduce\_while(get\_in(a\_params, \["b"\]), %{}, …

---

## [How to extract the data out of enum](https://forum.elixirforum.com/t/how-to-extract-the-data-out-of-enum/42275)

<div class="topic-metadata">

**Author:** [@yudy](https://forum.elixirforum.com/u/yudy)\
**Replies:** 4\
**Last updated:** [September 10, 2021, 6:44pm UTC](https://forum.elixirforum.com/t/how-to-extract-the-data-out-of-enum/42275 "2021-09-10T18:44:45Z")

</div>

How to filter below enumerable which has value more than one ? \[ {"12130", \[%{id: 1410, val: "12130"}, %{id: 1414, val: "12130"}\]}, {"65130", \[%{id: 1385, val: "65130"}\]}, {"65180", \[%{id: 1386, val: "65180"}\]} \] …

---

## [Passing list values to a function](https://forum.elixirforum.com/t/passing-list-values-to-a-function/40334)

<div class="topic-metadata">

**Author:** [@grangerelixx](https://forum.elixirforum.com/u/grangerelixx)\
**Replies:** 9\
**Last updated:** [June 9, 2021, 10:31pm UTC](https://forum.elixirforum.com/t/passing-list-values-to-a-function/40334 "2021-06-09T22:31:33Z")

</div>

I have a list of maps. For example, students = \[%{ sid: 1, name: "Bob", score: 80}, %{ sid: 2, name: "Kelly", score: 60},.....\] I have a function that accepts a single student map as a parameter, calculate\_percentage…

---

## [Iterating through a list](https://forum.elixirforum.com/t/iterating-through-a-list/39112)

<div class="topic-metadata">

**Author:** [@mathew4509](https://forum.elixirforum.com/u/mathew4509)\
**Replies:** 5\
**Last updated:** [April 21, 2021, 3:23am UTC](https://forum.elixirforum.com/t/iterating-through-a-list/39112 "2021-04-21T03:23:21Z")

</div>

I have a list say x = \["23gh", "56kh", "97mh"\] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------- Val = "23gh" iteration 2 -------- Val = "56kh" iteration …

---

## [Enum.member? on Ecto.Changeset](https://forum.elixirforum.com/t/enum-member-on-ecto-changeset/38805)

<div class="topic-metadata">

**Author:** [@mathew4509](https://forum.elixirforum.com/u/mathew4509)\
**Replies:** 2\
**Last updated:** [April 8, 2021, 3:03am UTC](https://forum.elixirforum.com/t/enum-member-on-ecto-changeset/38805 "2021-04-08T03:03:30Z")

</div>

I would like to perform the following, Let’s say, child = Ecto.Changeset and child.errors = \[parent\_id: "unavailable", \[validation: :required\]}\] I want to perform something like this, Enum.member?(child.errors, \[p…

---

## [How to implement Enumerable protocol for struct?](https://forum.elixirforum.com/t/how-to-implement-enumerable-protocol-for-struct/37269)

<div class="topic-metadata">

**Author:** [@vrod](https://forum.elixirforum.com/u/vrod)\
**Replies:** 12\
**Last updated:** [February 3, 2021, 10:32pm UTC](https://forum.elixirforum.com/t/how-to-implement-enumerable-protocol-for-struct/37269 "2021-02-03T22:32:32Z")

</div>

Sorry because many other people asked a similar question… but how do you implement the Enumerable protocol for a struct? I see the docs on https://hexdocs.pm/elixir/master/Enumerable.html but I do not follow how to actu…

---

## [Iterate over a list of maps and sum the result](https://forum.elixirforum.com/t/iterate-over-a-list-of-maps-and-sum-the-result/37274)

<div class="topic-metadata">

**Author:** [@hudsonbay](https://forum.elixirforum.com/u/hudsonbay)\
**Replies:** 8\
**Last updated:** [February 3, 2021, 8:15pm UTC](https://forum.elixirforum.com/t/iterate-over-a-list-of-maps-and-sum-the-result/37274 "2021-02-03T20:15:47Z")

</div>

I have this list of maps: list = \[%{price: 2, quantity:4}, %{price: 3, quantity: 5}\] For each map on the list, I need to multiply the price by the quantity and then sum all of the results. In this case it would be: (2…

---

## [Merge streams but run asynchronously](https://forum.elixirforum.com/t/merge-streams-but-run-asynchronously/36755)

<div class="topic-metadata">

**Author:** [@emre](https://forum.elixirforum.com/u/emre)\
**Replies:** 2\
**Last updated:** [January 11, 2021, 11:15am UTC](https://forum.elixirforum.com/t/merge-streams-but-run-asynchronously/36755 "2021-01-11T11:15:50Z")

</div>

Hello there, I have 3 streams, each streaming data from different sources. I want to merge these streams as well as run them in parallel. The Stream.concat function merges streams end to end, so when I use this combine…

---

## [Is it better during recursion to do \`list ++ \[add\_this\]\` or rather proper \`\[add\_this | list\]\` and finish with \`Enum.reverse/1\`?](https://forum.elixirforum.com/t/is-it-better-during-recursion-to-do-list-add-this-or-rather-proper-add-this-list-and-finish-with-enum-reverse-1/35900)

<div class="topic-metadata">

**Author:** [@mate](https://forum.elixirforum.com/u/mate)\
**Replies:** 7\
**Last updated:** [December 2, 2020, 12:45am UTC](https://forum.elixirforum.com/t/is-it-better-during-recursion-to-do-list-add-this-or-rather-proper-add-this-list-and-finish-with-enum-reverse-1/35900 "2020-12-02T00:45:25Z")

</div>

Hi all, I wrote this litle snippet: @spec map\_tuples\_and\_stop\_on\_error(list, {:error | :ok, list}, fun) :: {:error | :ok, list} def map\_tuples\_and\_stop\_on\_error(\[\], {result, elements}, fun) when result in \[:err…

---

## [How can I transform data using Enum functions?](https://forum.elixirforum.com/t/how-can-i-transform-data-using-enum-functions/35177)

<div class="topic-metadata">

**Author:** [@freewebwithme](https://forum.elixirforum.com/u/freewebwithme)\
**Replies:** 2\
**Last updated:** [October 27, 2020, 7:29pm UTC](https://forum.elixirforum.com/t/how-can-i-transform-data-using-enum-functions/35177 "2020-10-27T19:29:45Z")

</div>

Hi guys, I need your help. I have data like this \[ %Product{name: "product 1", category: "Food"}, %Product{name: "product 2", category: "Food"}, %Product{name: "product 3", category: "Food"}, %Product{name: "produc…

---

## [Check if value matches a field in a list of objects](https://forum.elixirforum.com/t/check-if-value-matches-a-field-in-a-list-of-objects/33900)

<div class="topic-metadata">

**Author:** [@Owens](https://forum.elixirforum.com/u/Owens)\
**Replies:** 3\
**Last updated:** [August 22, 2020, 12:51am UTC](https://forum.elixirforum.com/t/check-if-value-matches-a-field-in-a-list-of-objects/33900 "2020-08-22T00:51:26Z")

</div>

Hello all, I have a list of objects taken from the database (organizations), is there an efficient way to check if ANY of the objects in the list have a specific value to a field (employees == 5)?

---

## [Combine some list element pairs based on a condition?](https://forum.elixirforum.com/t/combine-some-list-element-pairs-based-on-a-condition/33357)

<div class="topic-metadata">

**Author:** [@itssasanka](https://forum.elixirforum.com/u/itssasanka)\
**Replies:** 2\
**Last updated:** [July 26, 2020, 6:23pm UTC](https://forum.elixirforum.com/t/combine-some-list-element-pairs-based-on-a-condition/33357 "2020-07-26T18:23:53Z")

</div>

Hi, I have a list like this \["blah", "12", "blaaa", "hello", "13"....\] Basically, some elements are numbers and others are normal strings. The list is always going to start with alphabetical strings. What I want to do…

---

## [Yaq - An Enumerable Queue for Elixir](https://forum.elixirforum.com/t/yaq-an-enumerable-queue-for-elixir/31684)

<div class="topic-metadata">

**Author:** [@NullOranje](https://forum.elixirforum.com/u/NullOranje)\
**Replies:** 13\
**Last updated:** [May 21, 2020, 8:30pm UTC](https://forum.elixirforum.com/t/yaq-an-enumerable-queue-for-elixir/31684 "2020-05-21T20:30:13Z")

</div>

While working on a work project, I found I needed a more Elixir-like queue versus the Erlang :queue module. So I decided to write one. I liked what I did, so I’m sharing it with others. Yaq (Yet another queue) is a do…

---

## [Learning how to use Enum.flat\_map\_reduce](https://forum.elixirforum.com/t/learning-how-to-use-enum-flat-map-reduce/31492)

<div class="topic-metadata">

**Author:** [@Maxximiliann](https://forum.elixirforum.com/u/Maxximiliann)\
**Replies:** 4\
**Last updated:** [May 13, 2020, 11:41pm UTC](https://forum.elixirforum.com/t/learning-how-to-use-enum-flat-map-reduce/31492 "2020-05-13T23:41:13Z")

</div>

Given: cars = %{ "Ferrari" =\> \[ %{color: "Blue", make: "Ferrari", mileage: 120012.481}, %{color: "Red", make: "Ferrari", mileage: 29831.021}, %{color: "Black", make: "Ferrari", mileage: 24030.674}, %{c…

---

## [Enum.map returns a list, not the enumerable type supplied](https://forum.elixirforum.com/t/enum-map-returns-a-list-not-the-enumerable-type-supplied/30720)

<div class="topic-metadata">

**Author:** [@wjeffery](https://forum.elixirforum.com/u/wjeffery)\
**Replies:** 8\
**Last updated:** [April 17, 2020, 6:17pm UTC](https://forum.elixirforum.com/t/enum-map-returns-a-list-not-the-enumerable-type-supplied/30720 "2020-04-17T18:17:31Z")

</div>

Hi, I was wondering why Enum.map returns a list and not the enumerable type provided. eg: iex\> Enum.map(%{a: 1, b: 2, c: 3}, fn x -\> x end) \[a: 1, b: 2, c: 3\] Wheres I would expect: iex\> Enum.map(%{a: 1, b: 2, c: 3},…

---

## [Add an artifical row into a stream](https://forum.elixirforum.com/t/add-an-artifical-row-into-a-stream/30531)

<div class="topic-metadata">

**Author:** [@petelacey](https://forum.elixirforum.com/u/petelacey)\
**Replies:** 2\
**Last updated:** [April 10, 2020, 10:09pm UTC](https://forum.elixirforum.com/t/add-an-artifical-row-into-a-stream/30531 "2020-04-10T22:09:35Z")

</div>

I have a table in Postgres holding file uploads. I also have a requirement to download a subset of these files as a zip file to the user. In order to keep a handle on memory and disk IO, I have managed to stream this co…

[Next page](https://forum.elixirforum.com/tag/enumerables/67.md?match_all_tags=true&page=1&tags%5B%5D=enumerables)
