Files
wren/core/map.html
Bob Nystrom 0a1c30118f Regenerate.
2015-03-13 07:58:04 -07:00

94 lines
5.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Map Class Wren</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic,700italic|Source+Code+Pro:400|Lato:400|Sanchez:400italic,400' rel='stylesheet' type='text/css'>
<!-- Tell mobile browsers we're optimized for them and they don't need to crop
the viewport. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
</head>
<body id="top" class="core">
<header>
<div class="page">
<div class="main-column">
<h1><a href="../">wren</a></h1>
<h2>a classy little scripting language</h2>
</div>
</div>
</header>
<div class="page">
<nav>
<ul>
<li><a href="./">Core Library</a></li>
</ul>
<section>
<h2>core classes</h2>
<ul>
<li><a href="bool.html">Bool</a></li>
<li><a href="class.html">Class</a></li>
<li><a href="fiber.html">Fiber</a></li>
<li><a href="fn.html">Fn</a></li>
<li><a href="list.html">List</a></li>
<li><a href="map.html">Map</a></li>
<li><a href="null.html">Null</a></li>
<li><a href="num.html">Num</a></li>
<li><a href="object.html">Object</a></li>
<li><a href="range.html">Range</a></li>
<li><a href="sequence.html">Sequence</a></li>
<li><a href="string.html">String</a></li>
</ul>
</section>
</nav>
<main>
<h1>Map Class</h1>
<p>An associative collection that maps keys to values. More details <a href="../maps.html">here</a>.</p>
<h3><strong>clear</strong>() <a href="#clear()" name="clear()" class="header-anchor">#</a></h3>
<p>Removes all entries from the map.</p>
<h3><strong>containsKey</strong>(key) <a href="#containskey(key)" name="containskey(key)" class="header-anchor">#</a></h3>
<p>Returns <code>true</code> if the map contains <code>key</code> or <code>false</code> otherwise.</p>
<h3><strong>count</strong> <a href="#count" name="count" class="header-anchor">#</a></h3>
<p>The number of entries in the map.</p>
<h3><strong>keys</strong> <a href="#keys" name="keys" class="header-anchor">#</a></h3>
<p>A <a href="sequence.html">Sequence</a> that can be used to iterate over the keys in the
map. Note that iteration order is undefined. All keys will be iterated over,
but may be in any order, and may even change between invocations of Wren.</p>
<h3><strong>iterate</strong>(iterator), <strong>iteratorValue</strong>(iterator) <a href="#iterate(iterator),-iteratorvalue(iterator)" name="iterate(iterator),-iteratorvalue(iterator)" class="header-anchor">#</a></h3>
<p>Implements the <a href="../control-flow.html#the-iterator-protocol">iterator protocol</a>
for iterating over the elements in the list.</p>
<h3><strong>remove</strong>(key) <a href="#remove(key)" name="remove(key)" class="header-anchor">#</a></h3>
<p>Removes [key] and the value associated with it from the map. Returns the value.</p>
<p>If the key was not present, returns <code>null</code>.</p>
<h3><strong>values</strong> <a href="#values" name="values" class="header-anchor">#</a></h3>
<p>A <a href="sequence.html">Sequence</a> that can be used to iterate over the values in the
map. Note that iteration order is undefined. All values will be iterated over,
but may be in any order, and may even change between invocations of Wren.</p>
<p>If multiple keys are associated with the same value, the value will appear
multiple times in the sequence.</p>
<h3><strong>[</strong>key<strong>]</strong> operator <a href="#[key]-operator" name="[key]-operator" class="header-anchor">#</a></h3>
<p>Gets the value associated with <code>key</code> in the map. If <code>key</code> is not present in the
map, returns <code>null</code>.</p>
<div class="codehilite"><pre><span class="kd">var</span> <span class="n">map</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;george&quot;</span><span class="o">:</span> <span class="s2">&quot;harrison&quot;</span><span class="p">,</span> <span class="s2">&quot;ringo&quot;</span><span class="o">:</span> <span class="s2">&quot;starr&quot;</span><span class="p">}</span>
<span class="n">IO</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="s2">&quot;ringo&quot;</span><span class="p">])</span> <span class="c1">// &quot;starr&quot;.</span>
<span class="n">IO</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="s2">&quot;pete&quot;</span><span class="p">])</span> <span class="c1">// &quot;null&quot;.</span>
</pre></div>
<h3><strong>[</strong>key<strong>]=</strong>(value) operator <a href="#[key]=(value)-operator" name="[key]=(value)-operator" class="header-anchor">#</a></h3>
<p>Associates <code>value</code> with <code>key</code> in the map. If <code>key</code> was already in the map, this
replaces the previous association.</p>
<p>It is a runtime error if the key is not a <a href="bool.html">Bool</a>,
<a href="class.html">Class</a>, <a href="null.html">Null</a>, <a href="num.html">Num</a>, <a href="range.html">Range</a>,
or <a href="string.html">String</a>.</p>
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives <a href="https://github.com/munificent/wren">on GitHub</a> &mdash; Made with &#x2764; by <a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a>.</p>
<div class="main-column">
</div>
</footer>
</body>
</html>