@@ -25,59 +25,58 @@ public struct Deck<Item: DeckItem>: Identifiable, Equatable {
25
25
public init (
26
26
id: UUID = UUID ( ) ,
27
27
name: String = " " ,
28
- items: [ Item ] ) {
28
+ items: [ Item ]
29
+ ) {
29
30
self . id = id
30
31
self . name = name
31
32
self . items = items
32
33
}
33
34
34
- /**
35
- The unique id of the deck.
36
- */
35
+ /// The unique id of the deck.
37
36
public let id : UUID
38
37
39
- /**
40
- The name of the deck.
41
- */
38
+ /// The name of the deck.
42
39
public let name : String
43
40
44
- /**
45
- The items that are added to the deck.
46
- */
41
+ /// The items that are added to the deck.
47
42
public var items : [ Item ]
48
43
}
49
44
50
45
public extension Deck {
51
46
52
- /**
53
- The index of a certain item, if any.
54
- */
47
+ /// The index of a certain item, if any.
55
48
func index( of item: Item ) -> Int ? {
56
49
items. firstIndex { $0. id == item. id }
57
50
}
58
51
59
- /**
60
- Move an item to the back of the deck.
61
- */
52
+ /// Move the first item to the back of the deck.
53
+ mutating func moveFirstItemToBack( ) {
54
+ guard let item = items. first else { return }
55
+ moveToBack ( item)
56
+ }
57
+
58
+ /// Move the last item to the front of the deck.
59
+ mutating func moveLastItemToFront( ) {
60
+ guard let item = items. last else { return }
61
+ moveToFront ( item)
62
+ }
63
+
64
+ /// Move an item to the back of the deck.
62
65
mutating func moveToBack( _ item: Item ) {
63
66
guard let index = index ( of: item) else { return }
64
67
let topItem = items. remove ( at: index)
65
68
items. append ( topItem)
66
69
}
67
70
68
- /**
69
- Move an item to the front of the deck.
70
- */
71
+ /// Move an item to the front of the deck.
71
72
mutating func moveToFront( _ item: Item ) {
72
73
guard let index = index ( of: item) else { return }
73
74
if items [ 0 ] . id == item. id { return }
74
75
let topItem = items. remove ( at: index)
75
76
items. insert ( topItem, at: 0 )
76
77
}
77
78
78
- /**
79
- Shuffle the deck.
80
- */
79
+ /// Shuffle the deck.
81
80
mutating func shuffle( ) {
82
81
items. shuffle ( )
83
82
}
0 commit comments