From 830f65cc8f442d50ce5e235bdb8dc559746b176e Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Mon, 1 Mar 2021 21:53:48 -0600 Subject: [PATCH 1/5] Update README.md --- README.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index aec180a..21071ef 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,89 @@ # Chain -> Chain.link.complete +## Example Code +```swift +let output = Chain.link( + .out { "First" }, + .link( .in { + print("Value: \($0)") + }, .multi( + [ + .multi([ + .end, + .end, + .end + ]), + .link(.out { + "Link" + }, .link( + .out { "Last" }, + .complete(.inout { value in + guard case .string(let value) = value else { + XCTFail() + return .void + } + + return .string("\(value) !!!") + }) + )) + ] + )) + ) + .run(name: "ChainTests-testOutput") +``` + +## Normal Chain Output +```swift +(lldb) po output +▿ Variable + ▿ array : 2 elements + ▿ 0 : Variable + - string : "First" + ▿ 1 : Variable + ▿ array : 2 elements + - 0 : E.Variable.void + ▿ 1 : Variable + ▿ array : 2 elements + ▿ 0 : Variable + ▿ array : 3 elements + ▿ 0 : Variable + ▿ array : 1 element + - 0 : E.Variable.void + ▿ 1 : Variable + ▿ array : 1 element + - 0 : E.Variable.void + ▿ 2 : Variable + ▿ array : 1 element + - 0 : E.Variable.void + ▿ 1 : Variable + ▿ array : 2 elements + ▿ 0 : Variable + - string : "Link" + ▿ 1 : Variable + ▿ array : 2 elements + ▿ 0 : Variable + - string : "Last" + ▿ 1 : Variable + ▿ array : 1 element + ▿ 0 : Variable + - string : "Last !!!" +``` +## Flattened Chain Output ```swift -Chain.link( - { print("Chain.link") }, - .complete { print("Chain.complete") } -) -.run() +(lldb) po output.flatten +▿ Variable + ▿ array : 8 elements + ▿ 0 : Variable + - string : "First" + - 1 : E.Variable.void + - 2 : E.Variable.void + - 3 : E.Variable.void + - 4 : E.Variable.void + ▿ 5 : Variable + - string : "Link" + ▿ 6 : Variable + - string : "Last" + ▿ 7 : Variable + - string : "Last !!!" ``` From bbad8c3d0b9268ad15681614d38b44ab8027798c Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Mon, 1 Mar 2021 22:03:42 -0600 Subject: [PATCH 2/5] Update README.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21071ef..fd47ea8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,18 @@ -# Chain +# Chain ⛓ + +*Chain of events* + +Use an enum to structure the call stack. + +```swift +public indirect enum Chain { + case end + case complete(E.Function?) + case link(E.Function, Chain) + case background(E.Function, Chain) + case multi([Chain]) +} +``` ## Example Code ```swift From 7ac5cac9b4f33c59260d10115706d73c513b7723 Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Tue, 2 Mar 2021 08:38:07 -0600 Subject: [PATCH 3/5] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1b1c8be --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Zach Eriksen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From c95faca0d69d23f22c15bdafaed1dc0aaa562e3d Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Tue, 2 Mar 2021 20:31:28 -0600 Subject: [PATCH 4/5] Update README.md --- README.md | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index fd47ea8..3cdea06 100644 --- a/README.md +++ b/README.md @@ -17,33 +17,42 @@ public indirect enum Chain { ## Example Code ```swift let output = Chain.link( - .out { "First" }, - .link( .in { - print("Value: \($0)") - }, .multi( - [ - .multi([ + .out { "First" }, + .link( + .in { + print("Value: \($0)") + }, + .multi( + [ + .multi( + [ .end, .end, .end - ]), - .link(.out { + ] + ), + .link( + .out { "Link" }, .link( .out { "Last" }, - .complete(.inout { value in - guard case .string(let value) = value else { - XCTFail() - return .void + .complete( + .inout { value in + guard case .string(let value) = value else { + XCTFail() + return .void + } + + return .string("\(value) !!!") } - - return .string("\(value) !!!") - }) - )) - ] - )) + ) + ) + ) + ] ) - .run(name: "ChainTests-testOutput") + ) +) +.run(name: "ChainTests-testOutput") ``` ## Normal Chain Output From e123195f7e5539bafdb8dacaa304661361083826 Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Tue, 2 Mar 2021 20:33:37 -0600 Subject: [PATCH 5/5] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3cdea06..f474ac8 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,8 @@ let output = Chain.link( ] ), .link( - .out { - "Link" - }, .link( + .out { "Link" }, + .link( .out { "Last" }, .complete( .inout { value in