@@ -61,7 +61,7 @@ void main() {
61
61
expect (fetchedAuthor.attributes['name' ], 'Alice' );
62
62
63
63
final fetchedComment =
64
- find ( fetchedPost.many ('comments' )! , response.included).single;
64
+ fetchedPost.many ('comments' )! . findIn ( response.included).single;
65
65
expect (fetchedComment.attributes['text' ], 'Hi Alice' );
66
66
});
67
67
@@ -145,12 +145,16 @@ void main() {
145
145
Include (['comments' ])
146
146
]).then ((r) {
147
147
expect (
148
- find (r.resource.many ('comments' )! , r.included)
148
+ r.resource
149
+ .many ('comments' )!
150
+ .findIn (r.included)
149
151
.single
150
152
.attributes['text' ],
151
153
'Secret comment' );
152
154
expect (
153
- find (r.resource.many ('comments' )! , r.included)
155
+ r.resource
156
+ .many ('comments' )!
157
+ .findIn (r.included)
154
158
.single
155
159
.attributes['text' ],
156
160
'Secret comment' );
@@ -179,9 +183,16 @@ void main() {
179
183
});
180
184
}
181
185
182
- /// Finds the referenced elements which are found in the [collection] .
183
- /// The resulting [Iterable] may contain fewer elements than referred by the
184
- /// relationship if the [collection] does not have all of them.
185
- Iterable <Resource > find (ToMany many, Iterable <Resource > collection) =>
186
- collection.where ((resource) =>
187
- many.any ((identifier) => identifier.identifies (resource)));
186
+ extension _ToManyExt on ToMany {
187
+ /// Finds the referenced elements which are found in the [collection] .
188
+ /// The resulting [Iterable] may contain fewer elements than referred by the
189
+ /// relationship if the [collection] does not have all of them.
190
+ Iterable <Resource > findIn (Iterable <Resource > collection) => collection.where (
191
+ (resource) => any ((identifier) => identifier.identifies (resource)));
192
+ }
193
+
194
+ extension _IdentifierExt on Identifier {
195
+ /// True if this identifier identifies the [resource] .
196
+ bool identifies (Resource resource) =>
197
+ type == resource.type && id == resource.id;
198
+ }
0 commit comments