-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
filterNoParams
and filterWithParams
to [Case]
- Loading branch information
Showing
5 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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,47 @@ | ||
import Mustache | ||
import SwiftSyntax | ||
|
||
struct ECases { | ||
fileprivate let underlying: EArray<ECase> | ||
|
||
init(elements: [EnumCaseElementSyntax]) throws { | ||
self.underlying = .init( | ||
underlying: try elements.map(ECase.init(from:)) | ||
) | ||
} | ||
} | ||
|
||
extension ECases: CustomStringConvertible { | ||
var description: String { | ||
self.underlying.description | ||
} | ||
} | ||
|
||
extension ECases: Sequence, MustacheSequence { | ||
func makeIterator() -> Array<ECase>.Iterator { | ||
self.underlying.makeIterator() | ||
} | ||
} | ||
|
||
extension ECases: CustomReflectable { | ||
var customMirror: Mirror { | ||
Mirror(reflecting: self.underlying) | ||
} | ||
} | ||
|
||
extension ECases: MustacheTransformable { | ||
func transform(_ name: String) -> Any? { | ||
if let defaultTransformed = self.underlying.transform(name) { | ||
return convertToCustomTypesIfPossible(defaultTransformed) | ||
} else { | ||
switch name { | ||
case "filterNoParams": | ||
return self.filter(\.parameters.underlying.underlying.isEmpty) | ||
case "filterWithParams": | ||
return self.filter({ !$0.parameters.underlying.underlying.isEmpty }) | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
} |
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