Hi,
On 4/03/2010 4:24 PM, Matthew Hazlett wrote:
The idea I had behind the range method was not just to create, but was
also to modify. By altering the index properties, you can create
staggered arrays and other such things. I havn't figured out how I
want to denote a set yet, I just have ranges supported for now.
Example:
http://mootools.net/shell/LrzTf/
Syntax: Array.Range(repeat, func)
Syntax: Array.Range([start, end], func);
Syntax: Array.Range([start, end, step], func);
Wouldn't it be simpler to have your function signatures take additional
parameters, rather than an array as a parameter?
Array.Range(repeat, func)
Array.Range(start, end, func)
Array.Range(start, end, step, func)
This is how i'd like to denote a set, it's just not valid javascript:
Array.Range({3, 7, 56, 92, 104}, function(index) {
// This will get an error
})
I don't think you'll be able to do this. :) You'll probably have to
settle for using array literals rather than object literals in this
instance.
Ideally, we'd be able to use something more akin to list comprehensions
[http://en.wikipedia.org/wiki/List_comprehension] (I personally like the
Haskell syntax). Writing
s= [ 2*x| x<- [0..12], x^2 > 3 ]
is just so clean and elegant. :)
- Barry
Not sent from my ?Phone
I could put quotes around it but that's ugly :-)
*From:* [email protected]
[mailto:[email protected]] *On Behalf Of *Fábio M. Costa
*Sent:* Wednesday, March 03, 2010 7:45 PM
*To:* [email protected]
*Subject:* Re: [Moo] Mootools Feature Suggestion
ive created a proof of concept:
http://mootools.net/shell/Y4Jpd/
--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces
2010/3/3 Fábio M. Costa <[email protected]
<mailto:[email protected]>>
Sorry the first example was incorrect:
Array.range(2); // returns [0,1]
--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces
On Wed, Mar 3, 2010 at 9:24 PM, Trevor Orr <[email protected]
<mailto:[email protected]>> wrote:
I could see the being useful once in a while, think it might be a good
addition to the more library.
On Wed, Mar 3, 2010 at 4:19 PM, hazlema <[email protected]
<mailto:[email protected]>> wrote:
In my opinion, it would be really cool if mootools could use a range
operator for numeric sets:
new Array.Range( [0, 10] );
would create an array with 11 empty elements
new Array.Range( [0, 10] , function() {
return new Element('div');
});
would create an array with 11 elements with div in each spot
Consider this code segment:
Days = new Array().Range( [0, 31], function(index) {
ele = new Element('div', {class: 'weekdays'});
if ((index % 7 == 0) || (index % 7 == 6))
ele.removeClass('weekdays').setClass('weekends');
return ele;
});
You got it, its a calendar
You could use it for existing arrays as well:
DaysArray.Range( [9, 11], function(index) {
this.Hide();
});
Just a thought I had while I was building an app, what do you think?
--
Not sent from my Apple ?Phone