Skip to content

Commit df3528f

Browse files
[ci skip] Added the last bits (for now) of documentation around LinkedList - TT
1 parent 011098e commit df3528f

39 files changed

+985
-173
lines changed

Workflow/LinkedList/Comparable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ extension LinkedList where Value : Comparable {
1717
return LinkedList(mergeSort(first, by: { $0 <= $1 }))
1818
}
1919

20+
/// max: Returns the maximum value in the comparable LinkedList
21+
/// - Returns: The maximum concrete value in the LinkedList or nil if there is none
2022
public func max() -> Value? {
2123
guard var m = first?.value else { return nil }
2224
forEach { m = Swift.max(m, $0.value) }
2325
return m
2426
}
2527

28+
/// min: Returns the minimum value in the comparable LinkedList
29+
/// - Returns: The minimum concrete value in the LinkedList or nil if there is none
2630
public func min() -> Value? {
2731
guard var m = first?.value else { return nil }
2832
forEach { m = Swift.min(m, $0.value) }

Workflow/LinkedList/Equatable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ extension LinkedList : Equatable where Value : Equatable {
1111
public static func == (lhs:LinkedList<Value>, rhs: LinkedList<Value>) -> Bool {
1212
return lhs.toArray() == rhs.toArray()
1313
}
14+
15+
/// contains: Returns a boolean indicating whether the given value is present in the LinkedList
16+
/// - Parameter element: The value to check against the LinkedList
17+
/// - Returns: A boolean indicating whether the supplied value is present
1418
public func contains(_ element:Element.Value) -> Bool {
1519
return contains(where: { $0.value == element })
1620
}

Workflow/LinkedList/NonMutatingOperations.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,35 @@ extension LinkedList {
4545
return LinkedList(mergeSort(first, by: comparator))
4646
}
4747

48+
/// dropFirst: Return a new version of the LinkedList without the first n items
49+
/// - Parameter n: The number of items to drop from the start of the list
50+
/// - Returns: A new version of the LinkedList without the first n items
51+
/// - Note: If you pass in an index that is out of the range of the LinkedList an empty LinkedList will be returned
4852
public func dropFirst(_ n: Int = 1) -> SubSequence {
4953
guard n > 0 else { return self }
5054
let copy = first?.copy().traverse(n)
5155
copy?.previous = nil
5256
return LinkedList(copy)
5357
}
5458

59+
/// dropFirst: Return a new version of the LinkedList without the last n items
60+
/// - Parameter n: The number of items to drop from the end of the list
61+
/// - Returns: A new version of the LinkedList without the last n items
62+
/// - Note: If you pass in an index that is out of the range of the LinkedList an empty LinkedList will be returned
5563
public func dropLast(_ n: Int = 1) -> SubSequence {
5664
guard n > 0 else { return self }
5765
let l = last?.copy().traverse(-n)
5866
l?.next = nil
5967
return LinkedList(l?.traverseToBeginning())
6068
}
6169

62-
public func drop(while predicate: (Element) throws -> Bool) rethrows -> SubSequence {
70+
/// drop(while): Return a new version of the LinkedList without the last n items
71+
/// - Parameter predicate: A closure that takes in the concrete type the node wraps and returns a boolean indicating whether it should drop from the list
72+
/// - Returns: A new version of the LinkedList without the last n items
73+
/// - Note: If you pass in an index that is out of the range of the LinkedList an empty LinkedList will be returned
74+
public func drop(while predicate: (Value) throws -> Bool) rethrows -> SubSequence {
6375
guard var l = last?.copy() else { return [] }
64-
while (try predicate(l)) {
76+
while (try predicate(l.value)) {
6577
if let prev = l.previous {
6678
l = prev
6779
} else { break }
@@ -70,16 +82,24 @@ extension LinkedList {
7082
return LinkedList(l)
7183
}
7284

85+
/// prefix(maxLength): Return a new version of the LinkedList with just the first n items
86+
/// - Parameter maxLength: The number of items to return
87+
/// - Returns: A new version of the LinkedList with just the first n items
88+
/// - Note: If you pass in an index that is greater than the size of the LinkedList you'll get the full list. If you send in an index smaller than the size of the LinkedList you'll get an empty list back.
7389
public func prefix(_ maxLength: Int) -> SubSequence {
7490
guard maxLength > 0 else { return [] }
7591
let copy = first?.copy().traverse(maxLength-1)
7692
copy?.next = nil
7793
return LinkedList(copy?.traverseToBeginning())
7894
}
7995

80-
public func prefix(while predicate: (Element) throws -> Bool) rethrows -> SubSequence {
96+
/// prefix(while): Return a new version of the LinkedList with just the first n items
97+
/// - Parameter predicate: A closure that takes in the concrete type the node wraps and returns a boolean indicating whether it should be included in the new list
98+
/// - Returns: A a new version of the LinkedList with just the first n items
99+
/// - Note: If you pass in an index that is greater than the size of the LinkedList you'll get the full list. If you send in an index smaller than the size of the LinkedList you'll get an empty list back.
100+
public func prefix(while predicate: (Value) throws -> Bool) rethrows -> SubSequence {
81101
guard var f = first?.copy() else { return [] }
82-
while (try predicate(f)) {
102+
while (try predicate(f.value)) {
83103
if let next = f.next {
84104
f = next
85105
} else { break }
@@ -88,14 +108,17 @@ extension LinkedList {
88108
return LinkedList(f)
89109
}
90110

111+
/// suffix(maxLength): Return a new version of the LinkedList with just the last n items
112+
/// - Parameter maxLength: The number of items to return
113+
/// - Returns: A new version of the LinkedList with just the last n items
91114
public func suffix(_ maxLength: Int) -> SubSequence {
92115
guard maxLength > 0 else { return [] }
93116
let copy = last?.copy().traverse(-(maxLength-1))
94117
copy?.previous = nil
95118
return LinkedList(copy)
96119
}
97120

98-
public func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator isSeparator: (Element) throws -> Bool) rethrows -> [SubSequence] {
121+
public func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Element) throws -> Bool) rethrows -> [SubSequence] {
99122
let splitNodeArr = (try? map { $0 }.split(maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences, whereSeparator: isSeparator)) ?? []
100123
return splitNodeArr.map { LinkedList($0.map { $0.value }) }
101124
}

WorkflowExampleTests/Mocks/WorkflowListener.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class WorkflowListener {
2121
NotificationCenter.default.addObserver(self, selector: #selector(workflowLaunched(notification:)), name: .workflowLaunched, object: nil)
2222
}
2323

24+
deinit {
25+
NotificationCenter.default.removeObserver(self)
26+
}
27+
2428
@objc func workflowLaunched(notification: Notification) {
2529
let dict = notification.object as? [String:Any?]
2630
workflow = dict?["workflow"] as? Workflow

WorkflowTests/LinkedListTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ class LinkedListTests: XCTestCase {
269269
func testPrefixWhile() {
270270
let list:LinkedList = [1, 2, 3, 4, 5, 6]
271271

272-
XCTAssertEqual(list.prefix(while: { $0.value != 2 }).last?.value, 2)
272+
XCTAssertEqual(list.prefix(while: { $0 != 2 }).last?.value, 2)
273273

274-
XCTAssertEqual(list.prefix(while: { $0.value != 4 }).last?.value, 4)
274+
XCTAssertEqual(list.prefix(while: { $0 != 4 }).last?.value, 4)
275275

276276
XCTAssertEqual(list.count, 6)
277277
}
@@ -330,7 +330,7 @@ class LinkedListTests: XCTestCase {
330330
func testDropWhile() {
331331
let list:LinkedList = [1, 2, 3, 4, 5, 6]
332332

333-
XCTAssertEqual(list.drop(while: { $0.value != 3}).last?.value, 3)
333+
XCTAssertEqual(list.drop(while: { $0 != 3}).last?.value, 3)
334334

335335
XCTAssertEqual(list.count, 6)
336336
}

docs/Classes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a title="Classes Reference"></a>
1515
<header>
1616
<div class="content-wrapper">
17-
<p><a href="index.html">DynamicWorkflow Docs</a> (69% documented)</p>
17+
<p><a href="index.html">DynamicWorkflow Docs</a> (78% documented)</p>
1818
</div>
1919
</header>
2020
<div class="content-wrapper">
@@ -230,7 +230,7 @@ <h4>Declaration</h4>
230230
</section>
231231
</section>
232232
<section id="footer">
233-
<p>&copy; 2019 <a class="link" href="https://github.com/Tyler-Keith-Thompson/Workflow" target="_blank" rel="external">Tyler.Thompson</a>. All rights reserved. (Last updated: 2019-10-05)</p>
233+
<p>&copy; 2019 <a class="link" href="https://github.com/Tyler-Keith-Thompson/Workflow" target="_blank" rel="external">Tyler.Thompson</a>. All rights reserved. (Last updated: 2019-10-07)</p>
234234
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
235235
</section>
236236
</article>

0 commit comments

Comments
 (0)