@@ -37,10 +37,42 @@ extension Rule {
3737 }
3838}
3939
40- @resultBuilder struct RuleBuilder {
41- static func buildBlock( _ components: Rule ... ) -> [ any Rule ] {
40+ @resultBuilder public struct RuleBuilder {
41+ public static func buildBlock( _ components: Rule ... ) -> [ any Rule ] {
4242 components
4343 }
44+
45+ public static func buildBlock( _ components: [ Rule ] ... ) -> [ Rule ] {
46+ components. flatMap { $0 }
47+ }
48+
49+ public static func buildExpression( _ expression: Rule ) -> [ Rule ] {
50+ [ expression]
51+ }
52+
53+ public static func buildExpression( _ expression: [ Rule ] ) -> [ Rule ] {
54+ expression
55+ }
56+
57+ public static func buildOptional( _ component: [ Rule ] ? ) -> [ Rule ] {
58+ component ?? [ ]
59+ }
60+
61+ public static func buildEither( first component: [ Rule ] ) -> [ Rule ] {
62+ component
63+ }
64+
65+ public static func buildEither( second component: [ Rule ] ) -> [ Rule ] {
66+ component
67+ }
68+
69+ public static func buildArray( _ components: [ [ Rule ] ] ) -> [ Rule ] {
70+ components. flatMap { $0 }
71+ }
72+
73+ public static func buildLimitedAvailability( _ component: [ Rule ] ) -> [ Rule ] {
74+ component
75+ }
4476}
4577
4678// MARK: Event rule
@@ -59,7 +91,7 @@ public struct EventRule: Rule {
5991 }
6092 }
6193
62- init ( event: RuleKit . Event , condition: @escaping ( RuleKit . DonatedEvent ) -> Bool ) {
94+ public init ( event: RuleKit . Event , condition: @escaping ( RuleKit . DonatedEvent ) -> Bool ) {
6395 self . event = event
6496 self . condition = condition
6597 }
@@ -84,11 +116,23 @@ public struct AnyOfRule: Rule {
84116 return false
85117 }
86118 }
119+
120+ public init( rules: [ any Rule ] ) {
121+ self . rules = rules
122+ }
123+
124+ public init( @RuleBuilder rules: ( ) - > [ any Rule] ) {
125+ self . rules = rules ( )
126+ }
87127}
88128
89129extension Rule where Self == AnyOfRule {
130+ public static func anyOf( _ rules: [ any Rule ] ) -> Rule {
131+ AnyOfRule ( rules: rules)
132+ }
133+
90134 public static func anyOf( @RuleBuilder _ rules: ( ) -> [ any Rule ] ) -> Rule {
91- AnyOfRule ( rules: rules ( ) )
135+ AnyOfRule ( rules: rules)
92136 }
93137}
94138
@@ -105,11 +149,23 @@ public struct AllOfRule: Rule {
105149 return true
106150 }
107151 }
152+
153+ public init( rules: [ any Rule ] ) {
154+ self . rules = rules
155+ }
156+
157+ public init( @RuleBuilder rules: ( ) - > [ any Rule] ) {
158+ self . rules = rules ( )
159+ }
108160}
109161
110162extension Rule where Self == AllOfRule {
163+ public static func allOf( _ rules: [ any Rule ] ) -> Rule {
164+ AllOfRule ( rules: rules)
165+ }
166+
111167 public static func allOf( @RuleBuilder _ rules: ( ) -> [ any Rule ] ) -> Rule {
112- AllOfRule ( rules: rules ( ) )
168+ AllOfRule ( rules: rules)
113169 }
114170}
115171
0 commit comments