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

Passing array into React stateless component

Following example from book Learn ReactJS, my attempt to pass an array in the same manner only yields errors. From the Github examples by authors:…
coscholl
  • 135
  • 1
  • 6
0
votes
1 answer

Pure D function to be calculated at run time (not compile time)

I am curious: If there is a pure D function, it can be calculated at compile time. What if I do not want a pure function to be calculated at compile time, but to calculate it at run time, how to do it? Example: static int result = f(); f is a pure…
porton
  • 5,214
  • 11
  • 47
  • 95
0
votes
1 answer

Can a redux reducer set 2 keys in the state which are almost copies of 1 another

I have a redux reducer as follows: function x(state = null, action){ switch(action){ case 'FILTER_DATA': { let { data } = state; let newData = someOperation(data); let s1 = deepCopy(newData); let s2 =…
Probosckie
  • 1,585
  • 4
  • 25
  • 40
0
votes
1 answer

Converting impure function to a pure function improvements - Scala

object IO { def getHtmlFromWebsiteViaHttp(link: String, apiKey: String = ""): String = { Http(link) .param("access_token", apiKey) .asString .body } } class SongService { private def retrieveSongId(songName: String):…
bob9123
  • 725
  • 1
  • 9
  • 31
0
votes
2 answers

Pure functions can change input values?

I'm studying functional programming and I just read about Pure functions. My question is: A pure function can change its parameters? Is this function pure? int a(Payment payment){ payment.setValue(payment.getValue() - 1); return payment.getValue()…
0
votes
1 answer

Will this be considered a pure reducer function in redux?

I have this reducer function and I am incrementing the value of voteScore by 1 inside it. Is this the right way to do it without breaking the constraint that reducer function should be pure function? function comment (state = {}, action) { ... …
limitlessriver
  • 751
  • 1
  • 6
  • 9
0
votes
4 answers

Javascript array map function keeps records of previous items of array

update Ok, so I've noticed that even though in isCategoryActive() function I'm mutating only the variable newCategories that was assigned a value from this.props.searchCategories the searchCategories prop changes value as well, therefore passing it…
Mateusz Mysiak
  • 548
  • 6
  • 19
0
votes
2 answers

Filter list of strings if a keyword matches in another list using Ramda

I have a list of URLs that have been returned from an API: const data = [ '/shoutouts', '/shoutouts/shoutout', '/news/news-story', '/example-page', '/another-page', '/stories/what-s-next', '/metrics', '/links', '/links/sprint', …
gosseti
  • 965
  • 16
  • 40
0
votes
1 answer

Have time in a pure manner in Fortran?

I am looking for a pure way to have access to time information. I thought about intrinsic functions and subroutines of standards compiler (date_and_time,cpu_time, system_clock, ltime, ctime, ...), the format do not really matter to me. I also…
R. N
  • 707
  • 11
  • 31
0
votes
0 answers

VHDL: pure function code has no coverage, but the function call is covered

I have the following VHDL code: pure function sInitSyncSupport( sState: TYPE_STATE; sCssi: TYPE_CSS_TO_SSM ) return TYPE_STATE is variable sStateOut: TYPE_STATE; begin sStateOut := sState; …
Mihai Hangiu
  • 588
  • 4
  • 13
0
votes
0 answers

Can a method with external dependencies on static configuration be considered pure?

I am having this class. config = $config; } public function getVal($key) { return $this->config[$key]; } } The…
Loupax
  • 4,728
  • 6
  • 41
  • 68
0
votes
1 answer

Array Spread Operator in Pure Function

In Redux Tutorial, they have used array spread operator a lot for writing reducers(which have to be pure functions) . Go through the following script. let a = { b : "ddff", c : "adxas" } let c = { b : "ssdds", c : "asdxasdsad" } let d =…
saiki4116
  • 323
  • 1
  • 4
  • 14
0
votes
0 answers

How can I set the output of now() in MySQL?

We want to run automated tests on MySQL stored procedures and functions wher the tests compare actual and expected values. The trouble is, even if we run a fixture script before each test, most of our routines can return different results given the…
Max Heiber
  • 14,346
  • 12
  • 59
  • 97
0
votes
1 answer

Segmentation fault with access to field using virtual pure function

I read a lot about the error with pure virtual call, but i didn't figure out what's wrong with my code: I programmed Chess game, using polymorphism. here some code: Piece.hpp (the Parent for all game pieces) class Piece { private: char _player; …
0
votes
1 answer

GCC and Clang: Turn off pure optimizations

I'm running a set of benchmarks comparing different libc string functions. The problem is that GCC and Clang are optimizing out the computations in the loops because the functions are marked "pure" and "const". Is there some way to either turn off…
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75
1 2 3
8
9