55namespace Valbeat \Result ;
66
77/**
8- * Result型は、成功(Ok)または失敗( Err)を表現します。
8+ * The Result type represents either success (Ok) or failure ( Err).
99 *
10- * 注意: instanceof による絞り込みでは型引数が失われます(PHPStan の既知の制限。
11- * Result<int, E> が型引数なしの Ok になり unwrap() は mixed になる)。
12- * 値を取り出す分岐では isOk() / isErr() で絞り込んでください。
10+ * Note: narrowing via instanceof loses the type arguments (a known PHPStan
11+ * limitation; Result<int, E> becomes an Ok without type arguments and unwrap()
12+ * returns mixed). In branches that extract the value, narrow with isOk() / isErr().
1313 *
14- * @template-covariant T 成功時の値の型
15- * @template-covariant E 失敗時のエラーの型
14+ * @template-covariant T the type of the success value
15+ * @template-covariant E the type of the error value
1616 *
1717 * @phpstan-sealed Ok|Err
1818 */
1919interface Result
2020{
2121 /**
22- * 結果が成功(Ok)の場合に true を返します .
22+ * Returns true if the result is a success (Ok) .
2323 *
2424 * @phpstan-assert-if-true Ok<T> $this
2525 * @phpstan-assert-if-false Err<E> $this
@@ -29,7 +29,7 @@ interface Result
2929 public function isOk (): bool ;
3030
3131 /**
32- * 結果が成功(Ok)でありコールバックが true を返す場合に true を返します .
32+ * Returns true if the result is a success (Ok) and the callback returns true .
3333 *
3434 * @param callable(T): bool $fn
3535 *
@@ -38,7 +38,7 @@ public function isOk(): bool;
3838 public function isOkAnd (callable $ fn ): bool ;
3939
4040 /**
41- * 結果が失敗(Err)の場合に true を返します .
41+ * Returns true if the result is a failure (Err) .
4242 *
4343 * @phpstan-assert-if-true Err<E> $this
4444 * @phpstan-assert-if-false Ok<T> $this
@@ -48,7 +48,7 @@ public function isOkAnd(callable $fn): bool;
4848 public function isErr (): bool ;
4949
5050 /**
51- * 結果が失敗(Err)でありコールバックが true を返す場合に true を返します .
51+ * Returns true if the result is a failure (Err) and the callback returns true .
5252 *
5353 * @param callable(E): bool $fn
5454 *
@@ -57,47 +57,47 @@ public function isErr(): bool;
5757 public function isErrAnd (callable $ fn ): bool ;
5858
5959 /**
60- * 成功値を返します。失敗の場合は例外を投げます .
60+ * Returns the success value. Throws an exception on failure .
6161 *
6262 * @return ($this is Ok<mixed> ? T : never)
6363 *
64- * @throws UnwrapException $this が Err の場合
64+ * @throws UnwrapException if $this is Err
6565 */
6666 public function unwrap (): mixed ;
6767
6868 /**
69- * エラー値を返します。成功の場合は例外を投げます .
69+ * Returns the error value. Throws an exception on success .
7070 *
7171 * @return ($this is Err<mixed> ? E : never)
7272 *
73- * @throws UnwrapException $this が Ok の場合
73+ * @throws UnwrapException if $this is Ok
7474 */
7575 public function unwrapErr (): mixed ;
7676
7777 /**
78- * 成功値を返します。失敗の場合は指定したメッセージで例外を投げます .
78+ * Returns the success value. On failure, throws an exception with the given message .
7979 *
80- * @param string $message 失敗時の例外メッセージ(エラー値の要約が付加されます)
80+ * @param string $message the exception message on failure (a summary of the error value is appended)
8181 *
8282 * @return ($this is Ok<mixed> ? T : never)
8383 *
84- * @throws UnwrapException $this が Err の場合
84+ * @throws UnwrapException if $this is Err
8585 */
8686 public function expect (string $ message ): mixed ;
8787
8888 /**
89- * エラー値を返します。成功の場合は指定したメッセージで例外を投げます .
89+ * Returns the error value. On success, throws an exception with the given message .
9090 *
91- * @param string $message 成功時の例外メッセージ(成功値の要約が付加されます)
91+ * @param string $message the exception message on success (a summary of the success value is appended)
9292 *
9393 * @return ($this is Err<mixed> ? E : never)
9494 *
95- * @throws UnwrapException $this が Ok の場合
95+ * @throws UnwrapException if $this is Ok
9696 */
9797 public function expectErr (string $ message ): mixed ;
9898
9999 /**
100- * 成功値またはデフォルト値を返します .
100+ * Returns the success value or a default value .
101101 *
102102 * @template U
103103 * @param U $default
@@ -106,7 +106,7 @@ public function expectErr(string $message): mixed;
106106 public function unwrapOr (mixed $ default ): mixed ;
107107
108108 /**
109- * 成功値またはクロージャーの結果を返します .
109+ * Returns the success value or the result of the closure .
110110 *
111111 * @template U
112112 * @param callable(E): U $fn
@@ -116,7 +116,7 @@ public function unwrapOr(mixed $default): mixed;
116116 public function unwrapOrElse (callable $ fn ): mixed ;
117117
118118 /**
119- * 成功値に関数を適用します .
119+ * Applies a function to the success value .
120120 *
121121 * @template U
122122 *
@@ -127,7 +127,7 @@ public function unwrapOrElse(callable $fn): mixed;
127127 public function map (callable $ fn ): self ;
128128
129129 /**
130- * エラー値に関数を適用します .
130+ * Applies a function to the error value .
131131 *
132132 * @template F
133133 *
@@ -138,7 +138,7 @@ public function map(callable $fn): self;
138138 public function mapErr (callable $ fn ): self ;
139139
140140 /**
141- * 成功値に副作用を適用します .
141+ * Applies a side effect to the success value .
142142 *
143143 * @param callable(T): void $fn
144144 *
@@ -147,7 +147,7 @@ public function mapErr(callable $fn): self;
147147 public function inspect (callable $ fn ): self ;
148148
149149 /**
150- * エラー値に副作用を適用します .
150+ * Applies a side effect to the error value .
151151 *
152152 * @param callable(E): void $fn
153153 *
@@ -156,7 +156,7 @@ public function inspect(callable $fn): self;
156156 public function inspectErr (callable $ fn ): self ;
157157
158158 /**
159- * 成功値に関数を適用するか、デフォルト値を返します .
159+ * Applies a function to the success value, or returns a default value .
160160 *
161161 * @template U
162162 *
@@ -168,7 +168,7 @@ public function inspectErr(callable $fn): self;
168168 public function mapOr (mixed $ default , callable $ fn ): mixed ;
169169
170170 /**
171- * 成功値に関数を適用するか、クロージャーの結果を返します .
171+ * Applies a function to the success value, or returns the result of the closure .
172172 *
173173 * @template U
174174 *
@@ -180,7 +180,7 @@ public function mapOr(mixed $default, callable $fn): mixed;
180180 public function mapOrElse (callable $ defaultFn , callable $ fn ): mixed ;
181181
182182 /**
183- * 成功の場合は第2の結果を返し、失敗の場合は最初のエラーを返します .
183+ * Returns the second result on success, or the first error on failure .
184184 *
185185 * @template U
186186 * @template F
@@ -192,9 +192,9 @@ public function mapOrElse(callable $defaultFn, callable $fn): mixed;
192192 public function and (self $ res ): self ;
193193
194194 /**
195- * 成功の場合は関数を適用し、失敗の場合は現在のエラーを返します .
195+ * Applies a function on success, or returns the current error on failure .
196196 *
197- * 関数は元と異なるエラー型を返せます。エラー型は E|F に合成されます .
197+ * The function may return a different error type; the error type is combined into E|F.
198198 *
199199 * @template U
200200 * @template F
@@ -206,7 +206,7 @@ public function and(self $res): self;
206206 public function andThen (callable $ fn ): self ;
207207
208208 /**
209- * 失敗の場合は第2の結果を返し、成功の場合は最初の値を返します .
209+ * Returns the second result on failure, or the first value on success .
210210 *
211211 * @template U
212212 * @template F
@@ -218,9 +218,9 @@ public function andThen(callable $fn): self;
218218 public function or (self $ res ): self ;
219219
220220 /**
221- * 失敗の場合は関数を適用し、成功の場合は現在の値を返します .
221+ * Applies a function on failure, or returns the current value on success .
222222 *
223- * 関数は元と異なる成功型を返せます。成功型は T|U に合成されます .
223+ * The function may return a different success type; the success type is combined into T|U.
224224 *
225225 * @template U
226226 * @template F
@@ -232,15 +232,15 @@ public function or(self $res): self;
232232 public function orElse (callable $ fn ): self ;
233233
234234 /**
235- * 成功の場合はokを、失敗の場合はerrを適用します .
235+ * Applies ok on success, or err on failure .
236236 *
237237 * @template U
238238 * @template V
239239 *
240- * @param callable(T): U $ok 成功値に適用する関数
241- * @param callable(E): V $err エラー値に適用する関数
240+ * @param callable(T): U $ok the function applied to the success value
241+ * @param callable(E): V $err the function applied to the error value
242242 *
243- * @return U|V 適用された関数の結果
243+ * @return U|V the result of the applied function
244244 */
245245 public function match (callable $ ok , callable $ err ): mixed ;
246246}
0 commit comments