Is this a pure function?

I have the following function:

  def timestamp(key: String)
  : String
  = Monoid.combine(key, Instant.now().getEpochSecond.toString)

and wanted to know if it is clean or not? A pure function for me is provided that the same input always returns the same output. But the above function, always given as one line, returns another line with a different time, which, in my opinion, is not clean.

+4
source share
2 answers

No, this is not pure by any definition that I know of. A good discussion of pure functions is here: https://alvinalexander.com/scala/fp-book/definition-of-pure-function . In determining Alvin's purity, he says:

A pure function does not have a β€œback door”, which means:

...

- -. , , -, ..; , , , -, ..

I/O, .

+5

, , . , .

  • . - , , / ( . ).

  • - , / ( - . ).

+2

Source: https://habr.com/ru/post/1691830/


All Articles