Question: I have an enumerable that goes through several transformation steps and a final filter step

E.g

```
[1,2,3,4,5,6,7,8,9].map{|i| i * 2}
                   .map{|i| i * i}
                   .filter{|i| i % 3 ==0 }
                   .each{|i| puts how_do_i_get_initial_value_here }
                   .or_the_initial_value_here

```

How do I get the initial value whose transformations satisfied the filter?

Thus in the above example, how do I end up with `[3,6,9]` instead of `[36, 144, 324]`

Answer: 
You could simply apply the transformations that you do in the two `map` calls directly in `filter`:

```rb
[1,2,3,4,5,6,7,8,9]
  .filter { |i| (i * 2)**2 % 3 == 0 }

```

Alternatively, you could keep the original value in a "tuple" as follows:

```rb
[1,2,3,4,5,6,7,8,9]
  .map { |i| [i, i] }
  .map { |a, b| [a, b * 2] }
  .map { |a, b| [a, b * b] }
  .filter { |a, b| b % 3 == 0 }
  .map { |a, _| a }

```
You are given a method:

```
def f(n)
  4 * n**2
end

```

where `f(n)` is the transformed value of an element `n` from the given array (as `(2 * n)*(2 * n) = 4 * n**2)`).

`f` is a 1-1 mapping, so it has an inverse method `g` (i.e., `g(f(n)) #=> n` for all integers `n`):

```
def g(m)
  Math.sqrt(m).round/2
end

```

(We need `.round` because of round-off errors.)

Suppose we have: 

```
arr
  #=> [1, 2, 3, 4, 5, 6, 7, 8, 9]

```

then

```
z = arr.map { |n| f(n) }.filter { |x| x % 3 == 0 }
  #=> [36, 144, 324] 

```

Then the inverse of these values is given by:

```
z.map { |m| g(m) }
  #=> [3, 6, 9]

```

Notice that:

```
arr.map { |n| f(n) }.filter { |x| x % 3 == 0 }

```

is the same as:

```
arr.filter { |x| x % 3 == 0 }.map { |n| f(n) }

```