For simplicity, let's say I want to create a function as such:

```
def powerOfTwo(n: Int): Int => Int

```

The output is another function that can be used as such that outputFunction(x) will give me 2^x.

the `n: Int` indicates the range of powers of 2 from 1 to n, that is `{2^1, 2^2, ... 2^n}`. I want these values to be pre-computed such that the resulting function `Int => Int` can be used by a simple lookup to obtain the corresponding element of that Array of powers of 2.

I wonder how can I accomplish that? Should I be making a `Class` which I then use to initialize some internal `var` object, and then pass around a function which will output the corresponding element of that `var` object?

Hope this is clear. Note that power of 2 is just an example. I am interested in how to implement this idea?