EmilyDirsh / hotwire-shell

Automatically exported from code.google.com/p/hotwire-shell
Other
0 stars 0 forks source link

uniq builtin #202

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A uniq builtin would often be useful.  I've written one.

* It only works on strings as it uses a dictionary internally which needs
immutable types as keys.
* It can use a string from a property, in which case the property string is
passed on, not the whole object.
* It can count (-c option) the instances.  In this case the output is
CountedObject (maybe this should be renamed) and there is a corresponding
renderer.

So, if history is made to work again (issue #192) then we could do

history | uniq -c | sort -r count | head

instead of writing a 10 line script ;-)

Original issue reported on code.google.com by dmi...@gmail.com on 27 Jun 2008 at 5:44

Attachments:

GoogleCodeExporter commented 9 years ago
The history pipe should of course be

history | py-map "it.split()[0]" | uniq -c | sort -r count | head

Original comment by dmi...@gmail.com on 27 Jun 2008 at 6:19

GoogleCodeExporter commented 9 years ago
CountedObject seems a bit overkill to me; can we just return a list of tuples?

The dictionary should also work on immutable sets, tuples, an integers too, no? 
 So
the documentation should basically say that only immutable data types can be 
used.

Also you should probably change the copyright on the file to yourself and not 
my name
since it's a nontrivial patch (> 10 lines).

Thanks for the patch!  If you agree with all the above feel free to go ahead 
and commit.

Original comment by cgwalt...@gmail.com on 29 Jun 2008 at 4:06

GoogleCodeExporter commented 9 years ago
We can return a list of tuples, but the display is not so good that way - have 
a play
and see what you think.  I've changed it to a tuple for now.  I can always 
change it
again later.  And I've changed the copyright and doc string.

Sending        hotwire/builtin.py
Adding         hotwire/builtins/uniq.py
Sending        hotwire/test_command.py
Transmitting file data ...
Committed revision 1282.

Original comment by dmi...@gmail.com on 4 Jul 2008 at 1:24