grangerelixx

grangerelixx

Function calling another function

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

result =
arg_1_val
|> Function_2(arg_2_val)

Here arg_1_val is my arg1, arg_2_val is my arg2 and arg3 will be passed in Function_2 definition.

Any inputs on what is the right approach to do this are appreciated.

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @grangerelixx, can you make this more concrete? You aren’t actually posting valid elixir code, which makes this hard to understand.

derek-zhou

derek-zhou

Of cause you can do that. However, I’d suggest you to finish some elixir tutorial on your own first, otherwise it is hard for other people to offer you help without knowing you have a baseline knowledge.

If you have prior experience with functional programming, the official Elixir tutorial should be enough. If you do not have any experience of functional programming, you can consider to purchase a book or some online tutorial that have more details than the official elixir tutorial.

eksperimental

eksperimental

I will replace “can” with “must”. Otherwise, if you call: function_with_arg3_equals_5(1, 2, 10000) it defeats the purpose of the funtion name, and you should be calling function_1/3

eksperimental

eksperimental

So your question is?

It will help if you can post real code.
My advice is not to create extra functions, just be explicit when you call a function. It will make your code more readable, and lean.

grangerelixx

grangerelixx

Thank you all for the inputs. I was able to execute what I intended to.

def function_1(arg1,arg2,arg3) do 
  does something
end

def function_with_arg3_equals_5(arg1,arg2,arg3 \\ 5) do
  function_1(arg1,arg2,arg3)
end

def function_with_arg3_equals_10(arg1,arg2,arg3 \\ 10) do
  function_1(arg1,arg2,arg3)
end

Where Next?

Popular in Questions Top

New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement