Skip to content

Commit

Permalink
Showing 39 changed files with 985 additions and 173 deletions.
4 changes: 4 additions & 0 deletions Workflow/LinkedList/Comparable.swift
Original file line number Diff line number Diff line change
@@ -17,12 +17,16 @@ extension LinkedList where Value : Comparable {
return LinkedList(mergeSort(first, by: { $0 <= $1 }))
}

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

/// min: Returns the minimum value in the comparable LinkedList
/// - Returns: The minimum concrete value in the LinkedList or nil if there is none
public func min() -> Value? {
guard var m = first?.value else { return nil }
forEach { m = Swift.min(m, $0.value) }
4 changes: 4 additions & 0 deletions Workflow/LinkedList/Equatable.swift
Original file line number Diff line number Diff line change
@@ -11,6 +11,10 @@ extension LinkedList : Equatable where Value : Equatable {
public static func == (lhs:LinkedList<Value>, rhs: LinkedList<Value>) -> Bool {
return lhs.toArray() == rhs.toArray()
}

/// contains: Returns a boolean indicating whether the given value is present in the LinkedList
/// - Parameter element: The value to check against the LinkedList
/// - Returns: A boolean indicating whether the supplied value is present
public func contains(_ element:Element.Value) -> Bool {
return contains(where: { $0.value == element })
}
33 changes: 28 additions & 5 deletions Workflow/LinkedList/NonMutatingOperations.swift
Original file line number Diff line number Diff line change
@@ -45,23 +45,35 @@ extension LinkedList {
return LinkedList(mergeSort(first, by: comparator))
}

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

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

public func drop(while predicate: (Element) throws -> Bool) rethrows -> SubSequence {
/// drop(while): Return a new version of the LinkedList without the last n items
/// - 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
/// - Returns: A new version of the LinkedList without the last n items
/// - Note: If you pass in an index that is out of the range of the LinkedList an empty LinkedList will be returned
public func drop(while predicate: (Value) throws -> Bool) rethrows -> SubSequence {
guard var l = last?.copy() else { return [] }
while (try predicate(l)) {
while (try predicate(l.value)) {
if let prev = l.previous {
l = prev
} else { break }
@@ -70,16 +82,24 @@ extension LinkedList {
return LinkedList(l)
}

/// prefix(maxLength): Return a new version of the LinkedList with just the first n items
/// - Parameter maxLength: The number of items to return
/// - Returns: A new version of the LinkedList with just the first n items
/// - 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.
public func prefix(_ maxLength: Int) -> SubSequence {
guard maxLength > 0 else { return [] }
let copy = first?.copy().traverse(maxLength-1)
copy?.next = nil
return LinkedList(copy?.traverseToBeginning())
}

public func prefix(while predicate: (Element) throws -> Bool) rethrows -> SubSequence {
/// prefix(while): Return a new version of the LinkedList with just the first n items
/// - 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
/// - Returns: A a new version of the LinkedList with just the first n items
/// - 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.
public func prefix(while predicate: (Value) throws -> Bool) rethrows -> SubSequence {
guard var f = first?.copy() else { return [] }
while (try predicate(f)) {
while (try predicate(f.value)) {
if let next = f.next {
f = next
} else { break }
@@ -88,14 +108,17 @@ extension LinkedList {
return LinkedList(f)
}

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

public func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator isSeparator: (Element) throws -> Bool) rethrows -> [SubSequence] {
public func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Element) throws -> Bool) rethrows -> [SubSequence] {
let splitNodeArr = (try? map { $0 }.split(maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences, whereSeparator: isSeparator)) ?? []
return splitNodeArr.map { LinkedList($0.map { $0.value }) }
}
4 changes: 4 additions & 0 deletions WorkflowExampleTests/Mocks/WorkflowListener.swift
Original file line number Diff line number Diff line change
@@ -21,6 +21,10 @@ class WorkflowListener {
NotificationCenter.default.addObserver(self, selector: #selector(workflowLaunched(notification:)), name: .workflowLaunched, object: nil)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

@objc func workflowLaunched(notification: Notification) {
let dict = notification.object as? [String:Any?]
workflow = dict?["workflow"] as? Workflow
6 changes: 3 additions & 3 deletions WorkflowTests/LinkedListTests.swift
Original file line number Diff line number Diff line change
@@ -269,9 +269,9 @@ class LinkedListTests: XCTestCase {
func testPrefixWhile() {
let list:LinkedList = [1, 2, 3, 4, 5, 6]

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

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

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

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

XCTAssertEqual(list.count, 6)
}
4 changes: 2 additions & 2 deletions docs/Classes.html
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">DynamicWorkflow Docs</a> (69% documented)</p>
<p><a href="index.html">DynamicWorkflow Docs</a> (78% documented)</p>
</div>
</header>
<div class="content-wrapper">
@@ -230,7 +230,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<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>
<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>
<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>
</section>
</article>
Loading

0 comments on commit df3528f

Please sign in to comment.