[removedAfterProceeding] Replaces filter and last with a last(where:) - MOB
MODIFY
Sources/Workflow/TypeErased/AnyWorkflow.swift
Sources/Workflow/TypeErased/AnyWorkflow.swift
@@ -42,6 +42,10 @@ extension AnyWorkflow: Sequence {
public func makeIterator() -> LinkedList<_WorkflowItem>.Iterator {
storageBase.makeIterator()
}
+
+ public func last(where predicate: (LinkedList<_WorkflowItem>.Element) throws -> Bool) rethrows -> LinkedList<_WorkflowItem>.Element? {
+ try storageBase.last(where: predicate)
+ }
}
extension AnyWorkflow {
@@ -69,15 +73,21 @@ extension AnyWorkflow {
fileprivate class AnyWorkflowStorageBase {
var orchestrationResponder: OrchestrationResponder?
- var count: Int { fatalError("Count not overriden by AnyWorkflowStorage") }
+ var count: Int { fatalError("Count not overridden by AnyWorkflowStorage") }
+
+ // https://github.com/Tyler-Keith-Thompson/Workflow/blob/master/STYLEGUIDE.md#type-erasure
+ // swiftlint:disable:next unavailable_function
+ func _abandon() { fatalError("_abandon not overridden by AnyWorkflowStorage") }
// https://github.com/Tyler-Keith-Thompson/Workflow/blob/master/STYLEGUIDE.md#type-erasure
// swiftlint:disable:next unavailable_function
- func _abandon() { fatalError("_abandon not overriden by AnyWorkflowStorage") }
+ func makeIterator() -> LinkedList<_WorkflowItem>.Iterator { fatalError("makeIterator not overridden by AnyWorkflowStorage") }
// https://github.com/Tyler-Keith-Thompson/Workflow/blob/master/STYLEGUIDE.md#type-erasure
// swiftlint:disable:next unavailable_function
- func makeIterator() -> LinkedList<_WorkflowItem>.Iterator { fatalError("makeIterator not overriden by AnyWorkflowStorage") }
+ func last(where predicate: (LinkedList<_WorkflowItem>.Element) throws -> Bool) rethrows -> LinkedList<_WorkflowItem>.Element? {
+ fatalError("last(where:) not overridden by AnyWorkflowStorage")
+ }
}
fileprivate final class AnyWorkflowStorage<F: FlowRepresentable>: AnyWorkflowStorageBase {
@@ -105,4 +115,8 @@ fileprivate final class AnyWorkflowStorage<F: FlowRepresentable>: AnyWorkflowSto
override func makeIterator() -> LinkedList<_WorkflowItem>.Iterator {
workflow.makeIterator()
}
+
+ override func last(where predicate: (LinkedList<_WorkflowItem>.Element) throws -> Bool) rethrows -> LinkedList<_WorkflowItem>.Element? {
+ try workflow.last(where: predicate)
+ }
}

MODIFY
Sources/WorkflowUIKit/UIKitPresenter.swift
Sources/WorkflowUIKit/UIKitPresenter.swift
@@ -62,7 +62,7 @@ open class UIKitPresenter: OrchestrationResponder {
}
public func complete(_ workflow: AnyWorkflow, passedArgs: AnyWorkflow.PassedArgs, onFinish: ((AnyWorkflow.PassedArgs) -> Void)?) {
- let lastInstance = workflow.filter { $0.value.instance != nil }.last
+ let lastInstance = workflow.last { $0.value.instance != nil }
if lastInstance?.value.metadata.persistence == .removedAfterProceeding,
let view = lastInstance?.value.instance?.underlyingInstance as? UIViewController {

[removedAfterProceeding] Replaces filter and last with a last(where:) - MOB