# \#function

**URL:** https://forum.elixirforum.com/tag/function/1465.md

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

---

## [Any update on a transpose function?](https://forum.elixirforum.com/t/any-update-on-a-transpose-function/73575)

<div class="topic-metadata">

**Author:** [@aloisdg](https://forum.elixirforum.com/u/aloisdg)\
**Replies:** 8\
**Last updated:** [December 8, 2025, 3:50pm UTC](https://forum.elixirforum.com/t/any-update-on-a-transpose-function/73575 "2025-12-08T15:50:37Z")

</div>

Any news about adding a transpose function to the standard lib? It was discussed on the mailing list in 2021, but nothing since. Transposing lists are a quite common operation and people often talk about it online like …

---

## [Default Parameters and Private Arities](https://forum.elixirforum.com/t/default-parameters-and-private-arities/72562)

<div class="topic-metadata">

**Author:** [@spammy](https://forum.elixirforum.com/u/spammy)\
**Replies:** 7\
**Last updated:** [September 18, 2025, 3:25pm UTC](https://forum.elixirforum.com/t/default-parameters-and-private-arities/72562 "2025-09-18T15:25:27Z")

</div>

Say we have a function: def func(a, b \\\\ 0) do I believe this generates func/1 and func/2. Is it possible to make func/2 private without spinning out a helper/implementation/do\_func/2 equivalent?

---

## [Default arguments best practices?](https://forum.elixirforum.com/t/default-arguments-best-practices/69832)

<div class="topic-metadata">

**Author:** [@amirOrbe](https://forum.elixirforum.com/u/amirOrbe)\
**Replies:** 17\
**Last updated:** [April 24, 2025, 6:16pm UTC](https://forum.elixirforum.com/t/default-arguments-best-practices/69832 "2025-04-24T18:16:32Z")

</div>

Hi everyone, I have a function with two parameters with default values something like: def(param1 \\\\ %{}, param2 \\\\ "") do ### end this is the best practice for do that? or you know another way ?

---

## [Elixir function doesn't continue if takes too long](https://forum.elixirforum.com/t/elixir-function-doesnt-continue-if-takes-too-long/61457)

<div class="topic-metadata">

**Author:** [@Codename-404](https://forum.elixirforum.com/u/Codename-404)\
**Replies:** 8\
**Last updated:** [February 6, 2024, 12:11pm UTC](https://forum.elixirforum.com/t/elixir-function-doesnt-continue-if-takes-too-long/61457 "2024-02-06T12:11:52Z")

</div>

def func do convert\_video.(1280) IO.puts(“Conversion done, starting to upload”) end I have this function, but problem is, if convert\_video.(1280) takes too long, IO.puts(“Conversion done, starting to upload”) line do…

---

## [Piping results of single-line function](https://forum.elixirforum.com/t/piping-results-of-single-line-function/61039)

<div class="topic-metadata">

**Author:** [@kwhite](https://forum.elixirforum.com/u/kwhite)\
**Replies:** 2\
**Last updated:** [January 17, 2024, 4:33am UTC](https://forum.elixirforum.com/t/piping-results-of-single-line-function/61039 "2024-01-17T04:33:20Z")

</div>

I just ran into this unexpected behavior. I had a short function that is piping its result into other functions. When I converted the short function to a one-liner, the result changed. I expected the EOL to terminate th…

---

## [What method can I use to create a function that counts duplicates and prints them out](https://forum.elixirforum.com/t/what-method-can-i-use-to-create-a-function-that-counts-duplicates-and-prints-them-out/60742)

<div class="topic-metadata">

**Author:** [@Etlevi](https://forum.elixirforum.com/u/Etlevi)\
**Replies:** 4\
**Last updated:** [January 3, 2024, 6:22pm UTC](https://forum.elixirforum.com/t/what-method-can-i-use-to-create-a-function-that-counts-duplicates-and-prints-them-out/60742 "2024-01-03T18:22:19Z")

</div>

I have a huge JSON file and what I want to accomplish is tell if there are any dupes in this json and which ones. This is basically to check if the JSON responses from a log are having duplicates or no hence verify if wh…

---

## [Unable to understand docs around many-to-many ecto preload functions](https://forum.elixirforum.com/t/unable-to-understand-docs-around-many-to-many-ecto-preload-functions/39089)

<div class="topic-metadata">

**Author:** [@jjabba](https://forum.elixirforum.com/u/jjabba)\
**Replies:** 4\
**Last updated:** [December 28, 2023, 11:26am UTC](https://forum.elixirforum.com/t/unable-to-understand-docs-around-many-to-many-ecto-preload-functions/39089 "2023-12-28T11:26:50Z")

</div>

Im trying to understand this section of the ecto documentation: For many\_to\_many - the function receives the IDs of the parent association and it must return a tuple with the parent id as the first element and the ass…

---

## [Adding new function to model module: Undefined function: Expected MyModule to define such a function or for it to be imported, but none are available](https://forum.elixirforum.com/t/adding-new-function-to-model-module-undefined-function-expected-mymodule-to-define-such-a-function-or-for-it-to-be-imported-but-none-are-available/54285)

<div class="topic-metadata">

**Author:** [@chrisdel101](https://forum.elixirforum.com/u/chrisdel101)\
**Replies:** 4\
**Last updated:** [March 3, 2023, 5:06pm UTC](https://forum.elixirforum.com/t/adding-new-function-to-model-module-undefined-function-expected-mymodule-to-define-such-a-function-or-for-it-to-be-imported-but-none-are-available/54285 "2023-03-03T17:06:27Z")

</div>

I’ve use the generators to create a project. Inside the project schema when I add a new function to the others that exist I get an error. In registration\_changeset I call validate\_email (given by the generartor) and co…

---

## [Function accepting only json as argument, with guard?](https://forum.elixirforum.com/t/function-accepting-only-json-as-argument-with-guard/47709)

<div class="topic-metadata">

**Author:** [@quda](https://forum.elixirforum.com/u/quda)\
**Replies:** 15\
**Last updated:** [January 21, 2023, 8:54am UTC](https://forum.elixirforum.com/t/function-accepting-only-json-as-argument-with-guard/47709 "2023-01-21T08:54:03Z")

</div>

Is it possible to create a function to accept only a valid json as parameter/argument ? Not map! Precisely, I need something that would perform as: def myFn(obj) when is\_json(obj) do ...function content... end I am aw…

---

## [How to get function definition file and line?](https://forum.elixirforum.com/t/how-to-get-function-definition-file-and-line/46911)

<div class="topic-metadata">

**Author:** [@fchabouis](https://forum.elixirforum.com/u/fchabouis)\
**Replies:** 10\
**Last updated:** [November 4, 2022, 3:23pm UTC](https://forum.elixirforum.com/t/how-to-get-function-definition-file-and-line/46911 "2022-11-04T15:23:59Z")

</div>

I would like to know if there is a way, in a mix project, to get information about where a function is defined? I would like, given a module name and function name, to know that this function is defined line 8 of foo.ex…

---

## [Function which calculates time from now to end date - strange warning from VSCode](https://forum.elixirforum.com/t/function-which-calculates-time-from-now-to-end-date-strange-warning-from-vscode/51325)

<div class="topic-metadata">

**Author:** [@MatijaL](https://forum.elixirforum.com/u/MatijaL)\
**Replies:** 10\
**Last updated:** [October 25, 2022, 6:39pm UTC](https://forum.elixirforum.com/t/function-which-calculates-time-from-now-to-end-date-strange-warning-from-vscode/51325 "2022-10-25T18:39:08Z")

</div>

Hello, I created a function which takes timedate as parameter in NaiveDateTime format. This date is an end date and the function has to calculate how much time is left from now to this end date. def time\_remaining(ends…

---

## [Functions opts - are there any guides or best practices on how to write them?](https://forum.elixirforum.com/t/functions-opts-are-there-any-guides-or-best-practices-on-how-to-write-them/49366)

<div class="topic-metadata">

**Author:** [@MatijaL](https://forum.elixirforum.com/u/MatijaL)\
**Replies:** 1\
**Last updated:** [August 8, 2022, 2:35pm UTC](https://forum.elixirforum.com/t/functions-opts-are-there-any-guides-or-best-practices-on-how-to-write-them/49366 "2022-08-08T14:35:56Z")

</div>

Hello, I’ve been learning Elixir and Phoenix for some time and I really enjoy them. I noticed that a lot of functions in Phoenix use opts as a function argument. opts is a list of function options and I thing I could us…

---

## [Test --cover not changing despite adding test?](https://forum.elixirforum.com/t/test-cover-not-changing-despite-adding-test/49370)

<div class="topic-metadata">

**Author:** [@CherryPoppins](https://forum.elixirforum.com/u/CherryPoppins)\
**Replies:** 6\
**Last updated:** [August 5, 2022, 9:05pm UTC](https://forum.elixirforum.com/t/test-cover-not-changing-despite-adding-test/49370 "2022-08-05T21:05:44Z")

</div>

I’m having trouble understanding how test --cover is working. I see a module has 0% coverage, add a test for the function defined in that module and test --cover still says 0% for that module. Also, not sure why it is fl…

---

## [Recursive function to iterate over a list](https://forum.elixirforum.com/t/recursive-function-to-iterate-over-a-list/43710)

<div class="topic-metadata">

**Author:** [@CommandoSev](https://forum.elixirforum.com/u/CommandoSev)\
**Replies:** 6\
**Last updated:** [November 10, 2021, 2:26am UTC](https://forum.elixirforum.com/t/recursive-function-to-iterate-over-a-list/43710 "2021-11-10T02:26:31Z")

</div>

How to write a recursive function, which iterates over a list and checks if an element is in that list in elixir?

---

## [Elixir does not recognize a varibale and extends it as a function. Why does this happen?](https://forum.elixirforum.com/t/elixir-does-not-recognize-a-varibale-and-extends-it-as-a-function-why-does-this-happen/42857)

<div class="topic-metadata">

**Author:** [@code](https://forum.elixirforum.com/u/code)\
**Replies:** 5\
**Last updated:** [October 7, 2021, 2:24pm UTC](https://forum.elixirforum.com/t/elixir-does-not-recognize-a-varibale-and-extends-it-as-a-function-why-does-this-happen/42857 "2021-10-07T14:24:54Z")

</div>

Here is my code: defmodule HW3A do def onepad(int, n \\\\ 0, list \\\\ \[\]) do case n do ^int -\> list \_ -\> onepad(int, n + 1, list ++ \[:rand.uniform(int)\]) end end defp string\_to\_…

---

## [How to assign a function to a specific version of Elixir](https://forum.elixirforum.com/t/how-to-assign-a-function-to-a-specific-version-of-elixir/42113)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 1\
**Last updated:** [September 3, 2021, 3:04am UTC](https://forum.elixirforum.com/t/how-to-assign-a-function-to-a-specific-version-of-elixir/42113 "2021-09-03T03:04:10Z")

</div>

Hello, I have a library that I want to update it and add some features, but some of my user do not want to update their elixir version. Then there is a question how can I add some function to my module when old version …

---

## [Function calling another function](https://forum.elixirforum.com/t/function-calling-another-function/39182)

<div class="topic-metadata">

**Author:** [@grangerelixx](https://forum.elixirforum.com/u/grangerelixx)\
**Replies:** 7\
**Last updated:** [April 23, 2021, 7:34pm UTC](https://forum.elixirforum.com/t/function-calling-another-function/39182 "2021-04-23T19:34:10Z")

</div>

I have a function Function\_1(arg1,arg2,arg3) I would like to call Function\_1 in another function Function\_2( ) where only arg3 is passed like arg3 \\\\ :hello And I would like to use Function\_2( ) in my code like this r…

---

## [How do I load ecto structs from a postgresql function?](https://forum.elixirforum.com/t/how-do-i-load-ecto-structs-from-a-postgresql-function/36112)

<div class="topic-metadata">

**Author:** [@jjabba](https://forum.elixirforum.com/u/jjabba)\
**Replies:** 3\
**Last updated:** [December 12, 2020, 6:22am UTC](https://forum.elixirforum.com/t/how-do-i-load-ecto-structs-from-a-postgresql-function/36112 "2020-12-12T06:22:57Z")

</div>

I’ve defined a table in postgresql to store a NonBinarySearchTree. The table is named nodes. Each row contains an id, and optionally a parent\_id (as a self referencing foreign key). For ease and convenience i’ve define…

---

## [Accessing protected functions](https://forum.elixirforum.com/t/accessing-protected-functions/35435)

<div class="topic-metadata">

**Author:** [@Ettu\_R](https://forum.elixirforum.com/u/Ettu_R)\
**Replies:** 3\
**Last updated:** [November 9, 2020, 11:28am UTC](https://forum.elixirforum.com/t/accessing-protected-functions/35435 "2020-11-09T11:28:49Z")

</div>

Im trying to understand creating and accessing protected functions. I have following simple code, but I’m getting error Im trying to call public function which in turn calls inside a protected function. What is going w…

---

## [Different/simple ways to implement some\_function() and some\_function!() that raises exception](https://forum.elixirforum.com/t/different-simple-ways-to-implement-some-function-and-some-function-that-raises-exception/33783)

<div class="topic-metadata">

**Author:** [@benhoven](https://forum.elixirforum.com/u/benhoven)\
**Replies:** 12\
**Last updated:** [August 18, 2020, 11:45pm UTC](https://forum.elixirforum.com/t/different-simple-ways-to-implement-some-function-and-some-function-that-raises-exception/33783 "2020-08-18T23:45:06Z")

</div>

Hi Everybody ;-), Based on my understanding the proper Elixir way is to implement functions that return :ok or :error instead of raise exception. And then if there is a need you can implement a function with the same na…

---

## [dealing with optional arguments via keyword list - my own take](https://forum.elixirforum.com/t/dealing-with-optional-arguments-via-keyword-list-my-own-take/33700)

<div class="topic-metadata">

**Author:** [@benhoven](https://forum.elixirforum.com/u/benhoven)\
**Replies:** 10\
**Last updated:** [August 12, 2020, 4:19pm UTC](https://forum.elixirforum.com/t/dealing-with-optional-arguments-via-keyword-list-my-own-take/33700 "2020-08-12T16:19:45Z")

</div>

Hi Everybody, I spent some time testing and trying different ways how to pass, process and use optional opts in a function argument. Ideally I’d like to settle on a single piece of code - something I can use in all my …

---

## [Capitalization of filenames](https://forum.elixirforum.com/t/capitalization-of-filenames/33308)

<div class="topic-metadata">

**Author:** [@roostercrab](https://forum.elixirforum.com/u/roostercrab)\
**Replies:** 2\
**Last updated:** [July 23, 2020, 11:26pm UTC](https://forum.elixirforum.com/t/capitalization-of-filenames/33308 "2020-07-23T23:26:12Z")

</div>

Hello, I am trying to teach Elixir to some intro to programming students, and they had a strange experience when running a simple program that wouldn’t work until they capitalized the filename like the module. We are a…

---

## [How to return values with if/else and if condition in function](https://forum.elixirforum.com/t/how-to-return-values-with-if-else-and-if-condition-in-function/29797)

<div class="topic-metadata">

**Author:** [@Suzaku\_Sakuya](https://forum.elixirforum.com/u/Suzaku_Sakuya)\
**Replies:** 5\
**Last updated:** [March 13, 2020, 2:34am UTC](https://forum.elixirforum.com/t/how-to-return-values-with-if-else-and-if-condition-in-function/29797 "2020-03-13T02:34:37Z")

</div>

Hi everyone, I am new to Elixir. I have a function and in this function: if type == "followers" do users = .... else users = .... end if options != nil do users = .... end How can I do this and make sure that th…

---

## [Testing functions that return other functions](https://forum.elixirforum.com/t/testing-functions-that-return-other-functions/29791)

<div class="topic-metadata">

**Author:** [@samuelludwig](https://forum.elixirforum.com/u/samuelludwig)\
**Replies:** 4\
**Last updated:** [March 12, 2020, 6:34pm UTC](https://forum.elixirforum.com/t/testing-functions-that-return-other-functions/29791 "2020-03-12T18:34:21Z")

</div>

I have a function (myfun/1) that takes in a list of characters, and depending on the characters in the list, returns a list of named functions (that are defined in the same module)–which will be applied at a later time. …

---

## [Remove Phoenix functions from ExDoc View pages?](https://forum.elixirforum.com/t/remove-phoenix-functions-from-exdoc-view-pages/23620)

<div class="topic-metadata">

**Author:** [@Rich\_Morin](https://forum.elixirforum.com/u/Rich_Morin)\
**Replies:** 7\
**Last updated:** [July 2, 2019, 7:15pm UTC](https://forum.elixirforum.com/t/remove-phoenix-functions-from-exdoc-view-pages/23620 "2019-07-02T19:15:49Z")

</div>

ExDoc adds documentation for several Phoenix functions to each of my View pages: \_\_phoenix\_recompile\_\_?() \_\_resource\_\_() \_\_templates\_\_() render(template, assigns \\\\ %{}) template\_not\_found(template, assigns) These ent…

---

## [How to use anonymous functions in configuration files?](https://forum.elixirforum.com/t/how-to-use-anonymous-functions-in-configuration-files/23069)

<div class="topic-metadata">

**Author:** [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Replies:** 3\
**Last updated:** [June 11, 2019, 12:51pm UTC](https://forum.elixirforum.com/t/how-to-use-anonymous-functions-in-configuration-files/23069 "2019-06-11T12:51:52Z")

</div>

Background I have a configuration file called test.exs that does not work because it has an anonymous function: # stub for fire function config :my\_aop, fire: fn(\_pool\_name, \_endpoint) -\> {:ok, :received} end And it …

---

## [Elixir function call on pattern match](https://forum.elixirforum.com/t/elixir-function-call-on-pattern-match/22319)

<div class="topic-metadata">

**Author:** [@xoron](https://forum.elixirforum.com/u/xoron)\
**Replies:** 3\
**Last updated:** [May 9, 2019, 9:43pm UTC](https://forum.elixirforum.com/t/elixir-function-call-on-pattern-match/22319 "2019-05-09T21:43:07Z")

</div>

i need to call function and function get map in argument and i also extract one property from map to use in guard and i also need other property on map in function i want my function to take only single argument and no…

---

## [Use cases of coroutines in elixir](https://forum.elixirforum.com/t/use-cases-of-coroutines-in-elixir/21488)

<div class="topic-metadata">

**Author:** [@actor](https://forum.elixirforum.com/u/actor)\
**Replies:** 6\
**Last updated:** [April 9, 2019, 6:21pm UTC](https://forum.elixirforum.com/t/use-cases-of-coroutines-in-elixir/21488 "2019-04-09T18:21:26Z")

</div>

I am new to elixir and also the concept of co-routines. I am trying to warp my head around how we can make use of time slice like explained here https://stackoverflow.com/a/19033882/492293 Lets say i have a list with 10…

---

## [Can we measure module and function usage?](https://forum.elixirforum.com/t/can-we-measure-module-and-function-usage/21370)

<div class="topic-metadata">

**Author:** [@Rich\_Morin](https://forum.elixirforum.com/u/Rich_Morin)\
**Replies:** 4\
**Last updated:** [April 3, 2019, 10:25pm UTC](https://forum.elixirforum.com/t/can-we-measure-module-and-function-usage/21370 "2019-04-03T22:25:40Z")

</div>

I think it would be interesting and possibly useful to gather statistics on module and function usage. For example, when I did a quick check on module use in my code base, I got these numbers: Enum.\* (268) Map.\* (63) S…
