Skip to content

Commit 8fcb7e4

Browse files
author
Simon Whitaker
committed
Make allItems a var
1 parent 23770dd commit 8fcb7e4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Multiset/Multiset.playground/Contents.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ set.add("Baz")
1616
set.count
1717
set.count(for: "Foo")
1818

19-
set.allItems()
19+
set.allItems
20+

Multiset/Multiset.playground/Sources/Multiset.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ public struct Multiset<T: Hashable> {
5555
return self.storage[key] ?? 0
5656
}
5757

58-
public func allItems() -> [T] {
59-
var result = Array<T>()
60-
for (key, count) in self.storage {
61-
for _ in 0 ..< count {
62-
result.append(key)
58+
public var allItems: [T] {
59+
get {
60+
var result = Array<T>()
61+
for (key, count) in self.storage {
62+
for _ in 0 ..< count {
63+
result.append(key)
64+
}
6365
}
66+
return result
6467
}
65-
return result
6668
}
6769
}
6870

0 commit comments

Comments
 (0)