View previous topic :: View next topic |
Author |
Message |
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Thu May 25, 2006 1:47 am Post subject: mango.utils.Array? |
|
|
As just came up on the NG, basic common array functions are a must, so maybe Mango could have a mango.utils.Array module, analogous to mango.utils.Text and that in Cashew:
http://www.codemeu.com:81/~pontiff/projects/cashew/docs/ArrayUtils.html
Just some essentials for when you do a lot of array handling, but don't need the elaboration of mango.containers.
The Cashew code is, of course and as always, available for a launchpad to the Mango version, if it happens. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Thu May 25, 2006 9:05 am Post subject: |
|
|
Seconded.
These really should be provided by the language but untill then some good array templates are needed.
I'd also suggest 'bool contains' to search an array, 'T[] unique' , given two arrays would return a unique result set.
Charlie |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Thu May 25, 2006 12:13 pm Post subject: |
|
|
qbert wrote: | 'T[] unique' , given two arrays would return a unique result set. |
It may be that I just got out of bed, but I'm not sure I quite grasp what you mean. Is it to be something along the lines of PHP's array_diff() function?
http://us2.php.net/manual/en/function.array-diff.php
And also let me add a couple more suggestions myself: .intersect(T[], ...) and, if someone can come up with a good way to pull it off, a .filter(T[], ?) and .map(T{}, ?) ... my ColdC background just won't let me live without the looping expressions (map, hash, find, and filter). _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Thu May 25, 2006 12:22 pm Post subject: |
|
|
Almost , i mean like php's array_unique http://us2.php.net/manual/en/function.array-unique.php . I said it wrong earlier, it operates on just one array.
filter and intersect sound good.
I actually tried to implement most of those array_* php functions with templates , but ran into trouble when it got up to about 50+ templates. I can't remember exactly what the error was, I still have the code Ill try to dig it up.
Charlie |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Thu May 25, 2006 10:32 pm Post subject: |
|
|
Ahh, I get you then. Although, maybe .diff() would be good too, although it should probably return a new array rather than modify the source inline, since it'd act on more than one array.
--------------------------------------------------
Edit: I just added some of this to Cashew's utils. New functions:
bool contains (haystack, needle)
T[] diff (alpha, beta)
T[] intersect (alpha, beta)
void unique (haystack) _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|