Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Dictionary changes #13

Merged
merged 1 commit into from
May 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Source/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
#endif
}

public mutating func removeValueForKey(_ key: Key) -> Value? {
public mutating func removeValue(forKey key: Key) -> Value? {
makeUnique()
#if JAVA
if dictionary.containsKey(key) {
Expand All @@ -334,6 +334,12 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
dictionary = PlatformDictionary<Key,Value>()
unique = true
}

public func forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrows {
for item in self {
try body(item)
}
}

public var count: Int {
#if JAVA
Expand Down Expand Up @@ -387,23 +393,23 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/

public static class DictionaryHelper {
#if JAVA
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key,Value>) -> ISequence<(Key, Value)> {
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key, Value>) -> ISequence<(Key, Value)> {
for entry in val.entrySet() {
var item: (Key, Value) = (entry.Key, entry.Value)
var item: (key: Key, value: Value) = (entry.Key, entry.Value)
__yield item
}
}
#elseif CLR | ISLAND
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key,Value>) -> ISequence<(Key, Value)> {
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key, Value>) -> ISequence<(Key, Value)> {
for entry in val {
var item: (Key, Value) = (entry.Key, entry.Value)
var item: (key: Key, value: Value) = (entry.Key, entry.Value)
__yield item
}
}
#elseif COCOA
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key,Value>) -> ISequence<(Key, Value)> {
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key, Value>) -> ISequence<(Key, Value)> {
for entry in val {
var item: (Key, Value) = (entry, val[entry]?)
var item: (key: Key, value: Value) = (entry, val[entry]?)
__yield item
}
}
Expand Down