<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Prototype JavaScript framework - ObjectRange</title>
  <id>tag:www.prototypejs.org,2009:mephisto/api/objectRange</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://www.prototypejs.org:80/feed/api/objectRange/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.prototypejs.org:80/api/objectRange" rel="alternate" type="text/html"/>
  <updated>2007-05-20T10:51:46Z</updated>
  <entry xml:base="http://www.prototypejs.org:80/">
    <author>
      <name>Christophe</name>
    </author>
    <id>tag:www.prototypejs.org:80,2007-01-10:13027</id>
    <published>2007-01-10T08:45:00Z</published>
    <updated>2007-05-20T10:51:46Z</updated>
    <category term="ObjectRange"/>
    <link href="http://www.prototypejs.org:80/api/objectRange/include" rel="alternate" type="text/html"/>
    <title>include</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;include(value) -&gt; Boolean&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Determines whether the value is included in the range.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;include(value) -&gt; Boolean&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Determines whether the value is included in the range.&lt;/p&gt;
&lt;p&gt;This assumes the values in the range have a valid strict weak ordering (have valid semantics for the &lt;code&gt;&amp;lt;&lt;/code&gt; operator).  While &lt;code&gt;ObjectRange&lt;/code&gt; mixes in &lt;a href=&quot;/api/enumerable&quot;&gt;&lt;code&gt;Enumerable&lt;/code&gt;&lt;/a&gt;, this method overrides the default version of &lt;a href=&quot;/api/enumerable/include&quot;&gt;&lt;code&gt;include&lt;/code&gt;&lt;/a&gt;, and is way more efficient (it uses a maximum of two comparisons).&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$R(1, 10).include(5)
// -&gt; true

$R('a', 'h').include('x')
// -&gt; false

$R(1, 10).include(10)
// -&gt; true

$R(1, 10, true).include(10)
// -&gt; false
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org:80/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org:80,2007-01-06:12980</id>
    <published>2007-01-06T19:00:00Z</published>
    <updated>2007-03-13T06:57:18Z</updated>
    <category term="ObjectRange"/>
    <link href="http://www.prototypejs.org:80/api/objectRange" rel="alternate" type="text/html"/>
    <title>ObjectRange</title>
<content type="html">
            &lt;p&gt;Ranges represent an interval of values.  The value type just needs to be &#8220;compatible,&#8221; that is, to implement a &lt;code&gt;succ&lt;/code&gt; method letting us step from one value to the next (its &lt;em&gt;successor&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Prototype provides such a method for &lt;code&gt;Number&lt;/code&gt; and &lt;code&gt;String&lt;/code&gt;, but you are of course welcome to implement useful semantics in your own objects, in order to enable ranges based on them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ObjectRange&lt;/code&gt; mixes in &lt;a href=&quot;/api/enumerable&quot;&gt;&lt;code&gt;Enumerable&lt;/code&gt;&lt;/a&gt;, which makes ranges very versatile.  It takes care, however, to override the default code for &lt;a href=&quot;/api/objectRange/include&quot;&gt;&lt;code&gt;include&lt;/code&gt;&lt;/a&gt;, to achieve better efficiency.&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;ObjectRange&lt;/code&gt; does provide a constructor, the preferred way to obtain a range is to use the &lt;a href=&quot;/api/utility/dollar-r&quot;&gt;&lt;code&gt;$R&lt;/code&gt;&lt;/a&gt; utility function, which is strictly equivalent (only way more concise to use).&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;p&gt;The most common use of ranges is, undoubtedly, numerical:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$A($R(1, 5)).join(', ')
// -&gt; '1, 2, 3, 4, 5'

$R(1, 5).zip(['one', 'two', 'three', 'four', 'five'], function(tuple) {
  return tuple.join(' = ');
})
// -&gt; ['1 = one', '2 = two', '3 = three', '4 = four', '5 = five']
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Be careful with &lt;code&gt;String&lt;/code&gt; ranges&lt;/strong&gt;: as described in its &lt;a href=&quot;/api/string/succ&quot;&gt;&lt;code&gt;succ&lt;/code&gt;&lt;/a&gt; method, it does not use alphabetical boundaries, but goes all the way through the character table:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$A($R('a', 'e'))
// -&gt; ['a', 'b', 'c', 'd', 'e'], no surprise there

$A($R('ax', 'ba'))
// -&gt; Ouch!  Humongous array, starting as ['ax', 'ay', 'az', 'a{', 'a|', 'a}', 'a~'...]
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
</feed>
