ソースを参照

Move MapEntry to `js.lib.MapEntry` module. (#8757)

* Move MapEntry to new `js.lib.MapEntry` module.

* Rename MayEntry to KeyValue.
terurou 6 年 前
コミット
be528d916c
3 ファイル変更52 行追加33 行削除
  1. 39 0
      std/js/lib/KeyValue.hx
  2. 4 19
      std/js/lib/Map.hx
  3. 9 14
      std/js/lib/Set.hx

+ 39 - 0
std/js/lib/KeyValue.hx

@@ -0,0 +1,39 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package js.lib;
+
+/**
+	Key/value access helper.
+**/
+abstract KeyValue<K, V>(Array<Any>) {
+	public var key(get, never):K;
+	public var value(get, never):V;
+
+	inline function get_key():K {
+		return this[0];
+	}
+
+	inline function get_value():V {
+		return this[1];
+	}
+}

+ 4 - 19
std/js/lib/Map.hx

@@ -95,31 +95,16 @@ extern class Map<K, V> {
 	function values():js.lib.Iterator<V>;
 
 	/**
-		Returns a new `Iterator` object that contains an array of `MapEntry`
+		Returns a new `Iterator` object that contains an array of `KeyValue`
 		for each element in the `js.Map` object in insertion order.
 	**/
-	function entries():js.lib.Iterator<MapEntry<K, V>>;
+	function entries():js.lib.Iterator<KeyValue<K, V>>;
 
-	inline function iterator(): js.lib.HaxeIterator<V> {
+	inline function iterator():js.lib.HaxeIterator<V> {
 		return new HaxeIterator(this.values());
 	}
 
-	inline function keyValueIterator(): HaxeIterator<MapEntry<K,V>> {
+	inline function keyValueIterator():HaxeIterator<KeyValue<K, V>> {
 		return new HaxeIterator(this.entries());
 	}
-
 }
-
-/**
-	Key/value access helper for `js.Map.entries()` and `js.Set.entries()`.
-**/
-abstract MapEntry<K, V>(Array<Any>) {
-	public var key(get, never):K;
-	public var value(get, never):V;
-
-	inline function get_key():K
-		return this[0];
-
-	inline function get_value():V
-		return this[1];
-}

+ 9 - 14
std/js/lib/Set.hx

@@ -22,8 +22,6 @@
 
 package js.lib;
 
-import js.lib.Map.MapEntry;
-
 /**
 	The `js.Set` object lets you store unique values of any type, whether
 	primitive values or object references.
@@ -95,41 +93,38 @@ extern class Set<T> {
 		This is kept similar to the `js.Map` object, so that each entry has the
 		same value for its key and value here.
 	**/
-	function entries():js.lib.Iterator<MapEntry<T, T>>;
+	function entries():js.lib.Iterator<KeyValue<T, T>>;
 
-	inline function iterator(): HaxeIterator<T> {
+	inline function iterator():HaxeIterator<T> {
 		return new HaxeIterator(this.values());
 	}
 
-	inline function keyValueIterator(): SetKeyValueIterator<T> {
+	inline function keyValueIterator():SetKeyValueIterator<T> {
 		return new SetKeyValueIterator(this);
 	}
-
 }
 
 /**
 	key => value iterator for js.lib.Set, tracking the entry index for the key to match the behavior of haxe.ds.List
 **/
 class SetKeyValueIterator<T> {
-
-	final set: js.lib.Set<T>;
-	final values: HaxeIterator<T>;
+	final set:js.lib.Set<T>;
+	final values:HaxeIterator<T>;
 	var index = 0;
 
-	public inline function new(set: js.lib.Set<T>) {
+	public inline function new(set:js.lib.Set<T>) {
 		this.set = set;
 		this.values = new HaxeIterator(set.values());
 	}
 
-	public inline function hasNext() : Bool {
+	public inline function hasNext():Bool {
 		return values.hasNext();
 	}
 
-	public inline function next() : {key: Int, value: T} {
+	public inline function next():{key:Int, value:T} {
 		return {
 			key: index++,
 			value: values.next(),
 		};
 	}
-
-} 
+}