From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Example of an impure function

Example of an impure function

- [Instructor] In this example, we'll look at a useful function, but it's considered impure from the functional programming perspective. So the code is in this method called get current time rounded up to custom minute interval. So while I'm passing in a value of four minutes of interval time and it'll take my system clock on my computer and take the current time and round it up to the nearest minute based on this interval. So when I run it on my computer at the moment, I can see it's 8:07 on my clock and it's rounded it up to 8:08 and when this gets to 50 or when it gets to 60, I should say, we're back to zero. We'll see this value change. Now it's rounded it up to the next four minute interval and it would be 16 after that and so on. This is a useful function, perhaps for your application, but it's impure because given the same value of four, I get back different results. And the reason why is easy to see when…

Contents