Skip to content

Instantly share code, notes, and snippets.

@MrLotU
Last active June 22, 2019 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrLotU/a3ec8857871ee516a5bd36227976c7e7 to your computer and use it in GitHub Desktop.
Save MrLotU/a3ec8857871ee516a5bd36227976c7e7 to your computer and use it in GitHub Desktop.
protocol Commands { }
extension Command: Commands { }
@_functionBuilder
struct CommandsBuilder: Commands {
static func buildBlock(_ commands: Command...) -> CommandList {
return CommandList(commands: { commands })
}
static func buildExpression(_ commands: Command...) -> CommandList {
return CommandList(commands: { commands })
}
}
@_functionBuilder
struct CommandListBuilder: Commands {
static func buildBlock(_ commands: Command...) -> [Command] {
return commands
}
}
struct CommandList: Commands {
var commands: [Command]
init(@CommandListBuilder commands: () -> [Command]) {
self.commands = commands()
}
}
protocol Plugin {
associatedtype C: Commands
// var otherCommands: () -> Commands { get }
var commands: C { get }
}
struct PluginOne: Plugin {
@CommandsBuilder
var commands: some Commands {
// Error here
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
struct PluginTwo: Plugin {
var commands: some Commands {
// Works
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
struct PluginThree: Plugin {
var commands: some Commands {
// Works
CommandList {
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
}
protocol Commands { }
extension Command: Commands { }
@_functionBuilder
struct CommandsBuilder: Commands {
static func buildBlock(_ commands: Command...) -> CommandList {
return CommandList(commands: { commands })
}
static func buildExpression(_ commands: Command...) -> CommandList {
return CommandList(commands: { commands })
}
}
@_functionBuilder
struct CommandListBuilder: Commands {
static func buildBlock(_ commands: Command...) -> [Command] {
return commands
}
}
struct CommandList: Commands {
var commands: [Command]
init(@CommandListBuilder commands: () -> [Command]) {
self.commands = commands()
}
}
protocol Plugin {
associatedtype C: Commands
var commands: C { get }
}
@available(OSX 10.15.0, *)
struct PluginOne: Plugin {
@CommandsBuilder
var commands: some Commands {
// Error here. Cannot convert return expression of type 'CommandList' to return type 'some Commands'
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
@available(OSX 10.15.0, *)
struct PluginTwo: Plugin {
var commands: some Commands {
// Works
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
@available(OSX 10.15.0, *)
struct PluginThree: Plugin {
var commands: some Commands {
// Works
CommandList {
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment