andreaferretti / memo

Memoization for Nim
78 stars 10 forks source link

Add support for functions without arguments #7

Closed Rafflesiaceae closed 2 years ago

Rafflesiaceae commented 2 years ago

The implementation so far required functions to have arguments in order to be memoized, as their arguments were wrapped into a tuple which was then hashed and used for lookup in a table.

To support functions without arguments the cache is instead implemented as a simple Option type.

andreaferretti commented 2 years ago

Thank you for your contribution! Memoizing an argumentless function is a little weird, since one can just store the result without invoking the function again, but I guess it can be useful, for instance when working with some functions that have arguments and others that do not have them.