human
Write me a the Python program you requested given the following:
I found an interesting problem on https://www.codewars.com/kata/529a92d9aba78c356b000353:
### Context and Definitions

You are in charge of developing a new cool JavaScript library that provides functionality similar to that of [Underscore.js](http://underscorejs.org/).

You have started by adding a new  **list data type** to your library. You came up with a design of a data structure that represents an [algebraic data type](http://en.wikipedia.org/wiki/Algebraic_data_type) as a pair of elements:

```python
class Cons:
  def __init__(self, head, tail):
    self.head = head
    self.tail = tail
```

You are pretty smart, because using this new data type, we can easily build a list of elements. For instance, a list of numbers:

```python
numbers = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, None)))))
```

In a code review with your boss, you explained him how every *cons cell* contains a "value" in its head, and in its tail it contains either another cons cell or null. We know we have reached the end of the data structure when the tail is null.

So, your boss is pretty excited about this new data structure and wants to know if you will be able to build some more  functionality around it. In a demo you did this week for the rest of your team, in order to illustrate how this works, you showed them a method to transform a list of items of your list data type into a JavaScript array:

```python
  # added to the class implementation:
  def to_array(self):
    tail = self.tail
    new_tail = (tail.to_array() if tail is not None else [])
    return [self.head] + new_tail
```

And they were amazed when you simply did this:

```python
print(numbers.to_array())  # yields [1,2,3,4,5]
```

### The New Requirements

Now, the team is convinced that this is the way to go and they would like to build the library around this cool new data type, but they want you to provide a few more features for them so that they can start using this type in solving some real world problems.

You have been reading about a technique called  [applicative...

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is the Python program you requested.

class Cons:
    def __init__(self, head, tail):
        self.head = head
        self.tail = tail
      
    def to_array(self):
        return [self.head] + (self.tail.to_array() if self.tail is not None else [])
      
    @classmethod
    def from_array(cls, arr):
        if arr:
            return Cons(arr[0], Cons.from_array(arr[1:]))
    
    def filter(self, fn):
        return Cons.from_array(list(filter(fn, self.to_array())))
    
    def map(self, fn):
        return Cons.from_array(list(map(fn, self.to_array())))