Questions tagged [pure-function]

A function that always evaluates to the same result value given the same argument value(s) and that does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices.

124 questions
0
votes
1 answer

Updating an object with Entity Framework using Pure Functions

I am wondering how Entity Framework works with pure functions. I have an order class with an update status method. Instead of changing the property of the current instance, it returns a new instance with the property update. This works as…
Ashley
  • 422
  • 6
  • 18
0
votes
0 answers

Why tree-shaking remove the side-effects code?

Here is the code snippet: const bar = () => 11111 function foo(obj) { return bar(obj); } foo() It's obviously that foo is an impure function which has side effects, so webpack's tree-shaking will not remove it. But after I search for the bundle,…
Chor
  • 833
  • 1
  • 5
  • 14
0
votes
1 answer

Scala: passing impure function to a HoF

I came across a piece of scala code which makes use of map function in a very unexpected manner: myList.map(item => someImpureFunction(item)) someImpureFunction has return type Unit. Is it an acceptable way of doing FP?
Mandroid
  • 6,200
  • 12
  • 64
  • 134
0
votes
1 answer

How are NgRx Selectors and Reducers pure functions?

According to the NgRx documentation Reducers and Selectors are pure functions. "Reducers are pure functions in that they produce the same output for a given input." "Because selectors are pure functions, the last result can be returned when the…
Devesh Pradhan
  • 149
  • 1
  • 6
0
votes
1 answer

About ' testable result ' in pure function

In JavaScript there is a conception named pure function. One of its features is that it always returns a testable result. I am very confused with this. I'd like to know the definition and the goal and why of it.
catcatcat
  • 3
  • 1
0
votes
1 answer

why closures are part of scala or any functional programming language

By the definition closures are Scala Closures are functions which use one or more free variables and the return value of this function is dependent of these variable. The free variables are defined outside of the Closure Function and is not…
Vivek
  • 405
  • 1
  • 4
  • 14
0
votes
1 answer

What is a more functional way of iteratively summing a list of values while capturing each intermediate result?

The code below works as expected, but the map lambda is impure. How could I refactor this to make it pure. (No need to stick to calling map, we could reduce or whatever else here, I just want it to be pure) val entries = listOf( …
0
votes
0 answers

Can function which calls pure function can be called pure function?

Is it possible to call function which calls pure function can be called pure function? How I understand 'pure function' is the function that always give same output on same input. Then let's do image this case. const function1 = name => { …
lcpnine
  • 477
  • 1
  • 7
  • 16
0
votes
1 answer

I cannot find anything that is impure about my function

Seriously, I'm getting desperate finding what the issue is. I can't find the answer for days! React.StrictMode API causes our setState to be called twice, right? If it produces an error, then it means that somewhere in our setState callback is…
SnekNOTSnake
  • 1,157
  • 12
  • 24
0
votes
1 answer

Is it possible to write every function as "pure function" in Google Apps Script?

I am interested in functional programming, so I decided to try this approach on the scripting environment of my Google Sheets file, and you know that the scripting language is Google Apps Script, which is basically javascript. And it even supports…
0
votes
1 answer

Preventing the use of an overridden non-virtual function - The correct way?

So this is my first question. I've searched the site, found something and applied the suggestions given in them but I'm still unsure if I've done it the right way. I'm working on a template library and here's my implementation of BST class…
0
votes
1 answer

Can we return Function from a method in a thread-safe way?

private Function> someFunction(SomeRequest someRequest) { return serviceBean -> serviceBean.doSomething(someRequest) .next(); } Is the above method safe? If I create, say 10 threads, with different…
0
votes
1 answer

Side-effects: Is modifying local variables an external or internal effect?

I am learning about side-effects in functional programming. I know that external effects are effects that are observable outside the function, whereas internal effects are not visible from the outside. I would like to know whether modifying local…
ceno980
  • 2,003
  • 1
  • 19
  • 37
0
votes
2 answers

Which fake random function that generate most seemingly random number between 0 to 1?

Most random function I could find is a sequence function, it keep the last generated result as a seed of the next call I want a pure function that could be run on its own and could give seemingly random sequence given any number from start to end…
Thaina Yu
  • 1,372
  • 2
  • 16
  • 27
0
votes
2 answers

Is this not a pure function?

I am learning state management for web development, and come across this redux tutorial with the pure function as below. However the statement : "action.todo.id = state.todos.length + 1;" makes me suspect this pure function was ... IMPURE. Please…
T Luu
  • 3
  • 2
1 2 3
8 9