This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a8e73f
commit c5125c3
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Tests/TypeWrapperTests/ExampleImplementations/MoreOptions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// MoreOptions.swift | ||
// | ||
// | ||
// Created by Joseph Hinkle on 9/19/21. | ||
// | ||
|
||
import TypeWrapper | ||
|
||
// | ||
// implement for simple type (Bool) with more options | ||
// | ||
extension TypeWrapper { | ||
func boolMoreOptions(_ options: _BoolExtraOptions) throws -> AnyWithTypeWrapper { | ||
try self.send(options, as: { | ||
($0 as? _Bool)?.onReceive(input:) | ||
}) | ||
} | ||
} | ||
protocol _Bool { | ||
func onReceive(input: Any) throws -> AnyWithTypeWrapper | ||
} | ||
struct _BoolExtraOptions { | ||
let someBool: Any | ||
let otherBool: Any | ||
let op: String | ||
} | ||
extension AttemptIfConformsStruct: _Bool where Wrapped == Bool { | ||
public func onReceive(input: Any) throws -> AnyWithTypeWrapper { | ||
let options = input as! _BoolExtraOptions | ||
if let someBool: Bool = options.someBool as? Bool, | ||
let otherBool: Bool = options.otherBool as? Bool { | ||
if options.op == "||" { | ||
let result = someBool || otherBool | ||
return addTypeWrapper(result) | ||
} else if options.op == "&&" { | ||
let result = someBool && otherBool | ||
return addTypeWrapper(result) | ||
} else { | ||
fatalError("bad op") | ||
} | ||
} else { | ||
fatalError("bad data") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters