Hi,

I'm not sure to understand the real purpose of Vector.

Is that a new collection ?

Is that a list with a builtin map() function ?

Is it a  wrapper to other types ?

Should it be iterable ?


The clear need explained before is using fluent interface on a collection :

MyVector.strip().replace("A","E")

Why do we need Vector to behave like list. We just want to work on our
strings but with a cleaner/shorter/nicer syntax.

My idea (not totally clear in my mind) is that Vector should behave
quite like the type it wraps so having only one type.

I don't want a collection of strings, I want a MegaString (...) which I
can use exactly like alone string.

An iteration on Vector would iter like itertools.chain does.

At the end, I would only need one more method which would return an
iterable of the items like MyVector.explode()


For me Vector should be something like that :

class Vector:

    def __init__(self, a_list):
        self.data = a_list
        self._type = type(self.data[0])

        for data in self.data:
            if type(data) != self._type:
                raise TypeError

    def __getattr__(self, name):
        fn =  getattr(self._type, name)

        def wrapped(*args, **kwargs):
            self.data = [fn(i, *args, **kwargs) for i in self.data]
            return self
        return wrapped

    def explode(self):
          return iter(self.data)


I'm not saying it should only handle strings but it seems to be the
major use case.

Jimmy


Le 04/02/2019 à 17:12, David Mertz a écrit :
> On Mon, Feb 4, 2019 at 7:14 AM Kirill Balunov <kirillbalu...@gmail.com
> <mailto:kirillbalu...@gmail.com>> wrote:
>
>         len(v)   # -> 12
>
>         v[len]   # -> <Vector of [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]>
>
>
>     In this case you can apply any function,
>     even custom_linked_list frommy_inhouse_module.py. 
>
>
> I think I really like this idea.  Maybe as an extra spelling but still
> allow .apply() to do the same thing. It feels reasonably intuitive to
> me. Not *identical to* indexing in NumPy and Pandas, but sort of in
> the same spirit as predicative or selection based indices.
>
> What do other people on this thread think? Would you learn that
> easily? Could you teach it?
>  
>
>         >>> v[1:]  
>         <Vector of ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
>         'Sep', 'Oct', 'Nov', 'Dec']>  
>         >>> v[i[1:]] # some helper class `i`
>         <Vector of ['an', 'eb', 'ar', 'pr', 'ay', 'un', 'ul', 'ug',
>         'ep', 'ct', 'ov', 'ec']>  
>
>
> This feels more forced, unfortunately.  Something short would be good,
> but not sure I like this.  This is really just a short spelling of
> pandas.IndexSlice or numpy.s_  It came up in another thread some
> months ago, but there is another proposal to allow the obvious
> spelling `slice[start:stop:sep]` as a way of creating slices.
>
> Actually, I guess that's all halfway for the above.  We'd need to do
> this still:
>
>     v[itemgetter(IndexSlicer[1:])]
>
>  
> That's way too noisy.  I guess I just don't find the lowercase `i` to
> be iconic enough.  I think with a better SHORT name, I'd like:
>
>     v[Item[1:]]
>
>
>  Maybe that's not the name?
>
> -- 
> Keeping medicines from the bloodstreams of the sick; food
> from the bellies of the hungry; books from the hands of the
> uneducated; technology from the underdeveloped; and putting
> advocates of freedom in prisons.  Intellectual property is
> to the 21st century what the slave trade was to the 16th.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


Le 04/02/2019 à 17:12, David Mertz a écrit :
> On Mon, Feb 4, 2019 at 7:14 AM Kirill Balunov <kirillbalu...@gmail.com
> <mailto:kirillbalu...@gmail.com>> wrote:
>
>         len(v)   # -> 12
>
>         v[len]   # -> <Vector of [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]>
>
>
>     In this case you can apply any function,
>     even custom_linked_list frommy_inhouse_module.py. 
>
>
> I think I really like this idea.  Maybe as an extra spelling but still
> allow .apply() to do the same thing. It feels reasonably intuitive to
> me. Not *identical to* indexing in NumPy and Pandas, but sort of in
> the same spirit as predicative or selection based indices.
>
> What do other people on this thread think? Would you learn that
> easily? Could you teach it?
>  
>
>         >>> v[1:]  
>         <Vector of ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
>         'Sep', 'Oct', 'Nov', 'Dec']>  
>         >>> v[i[1:]] # some helper class `i`
>         <Vector of ['an', 'eb', 'ar', 'pr', 'ay', 'un', 'ul', 'ug',
>         'ep', 'ct', 'ov', 'ec']>  
>
>
> This feels more forced, unfortunately.  Something short would be good,
> but not sure I like this.  This is really just a short spelling of
> pandas.IndexSlice or numpy.s_  It came up in another thread some
> months ago, but there is another proposal to allow the obvious
> spelling `slice[start:stop:sep]` as a way of creating slices.
>
> Actually, I guess that's all halfway for the above.  We'd need to do
> this still:
>
>     v[itemgetter(IndexSlicer[1:])]
>
>  
> That's way too noisy.  I guess I just don't find the lowercase `i` to
> be iconic enough.  I think with a better SHORT name, I'd like:
>
>     v[Item[1:]]
>
>
>  Maybe that's not the name?
>
> -- 
> Keeping medicines from the bloodstreams of the sick; food
> from the bellies of the hungry; books from the hands of the
> uneducated; technology from the underdeveloped; and putting
> advocates of freedom in prisons.  Intellectual property is
> to the 21st century what the slave trade was to the 16th.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to