Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Mar 3, 2021
2 parents 20b069a + e123195 commit dc6c164
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 6 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
112 changes: 106 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,111 @@
# Chain
# Chain

> Chain.link.complete
*Chain of events*

Use an enum to structure the call stack.

```swift
Chain.link(
{ print("Chain.link") },
.complete { print("Chain.complete") }
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
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()
.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
(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 !!!"
```

0 comments on commit dc6c164

Please sign in to comment.