File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -83,17 +83,23 @@ final public function toArray(): array
83
83
// NOTE: IArrayListFactory
84
84
// -------------------------------------------------------------------------
85
85
#[Override]
86
- final public static function from (array $ elements ): static
86
+ final public static function from (iterable $ elements ): static
87
87
{
88
- return new static ($ elements );
88
+ if (is_array ($ elements )) {
89
+ return new static ($ elements );
90
+ }
91
+
92
+ return new static (iterator_to_array ($ elements ));
89
93
}
90
94
91
95
#[Override]
92
- final public static function tryFrom (array $ elements ): Result
96
+ final public static function tryFrom (iterable $ elements ): Result
93
97
{
98
+ $ elements = is_array ($ elements ) ? $ elements : iterator_to_array ($ elements );
99
+
94
100
return static ::isValid ($ elements )
95
101
->andThen (static fn () => static ::isValidCount ($ elements ))
96
- ->andThen (static fn () => Result \ok (static :: from ($ elements )));
102
+ ->andThen (static fn () => Result \ok (new static ($ elements )));
97
103
}
98
104
99
105
#[Override]
Original file line number Diff line number Diff line change @@ -20,20 +20,20 @@ interface IArrayListFactory
20
20
*
21
21
* @template TFromValue of TValue
22
22
*
23
- * @param array <int,TFromValue> $elements
23
+ * @param iterable <int,TFromValue> $elements
24
24
* @return static<TFromValue>
25
25
*/
26
- public static function from (array $ elements ): static ;
26
+ public static function from (iterable $ elements ): static ;
27
27
28
28
/**
29
29
* 信頼できないプリミティブ値からインスタンスを生成する
30
30
*
31
31
* @template TTryFromValue of TValue
32
32
*
33
- * @param array <int,TTryFromValue> $elements
33
+ * @param iterable <int,TTryFromValue> $elements
34
34
* @return Result<static<TTryFromValue>,ValueObjectError>
35
35
*/
36
- public static function tryFrom (array $ elements ): Result ;
36
+ public static function tryFrom (iterable $ elements ): Result ;
37
37
38
38
/**
39
39
* 空のコレクションを作成する
You can’t perform that action at this time.
0 commit comments