The current Optional.construct returns nil when the given JS value is null or undefined, butnilmeans a failure during decode here, so it's semantically wrong. Instead, it should return.some(nil)`.
Also, when Wrapped.construct returns nil, it means decode operation failed, so Optional.construct method should return nil. But it might be unclear that the returned Optional<Wrapped> value won't be implicitly casted to .some(nil), so I changed to return nil by guard statement explicitly.
The current
Optional.construct
returnsnil
when the given JS value isnull
orundefined, but
nilmeans a failure during decode here, so it's semantically wrong. Instead, it should return
.some(nil)`.Also, when
Wrapped.construct
returnsnil
, it means decode operation failed, soOptional.construct
method should returnnil
. But it might be unclear that the returnedOptional<Wrapped>
value won't be implicitly casted to.some(nil)
, so I changed to returnnil
byguard
statement explicitly.Original description
現在の実装ではJSの値として `null`, `undefined` の場合に、 `Optional.construct` が `nil` を返していますが、 これはデコードの失敗を意味するため間違っています。 適切に `Optional.none` がデコードできた状況なので、 `.some(nil)` を返す必要があります。 また、 `Wrapped.construct` が `nil` を返した場合は、 デコード失敗なので `nil` を返すべきですが、 ここで暗黙のキャストによって `.some(nil)` が返ってしまうかどうか分かりづらいと思ったので、 明示的に guard 文で分岐するように書き換えてみました。