Closed nikita-leonov closed 8 years ago
Looks good to me ✨
I have only one concern. Compiler doesn't infer type to use .some
alone.
let a = unit(2) // OK type inference
let b = .some(2) // Error type inference
let c = Optional<Int>.some(2) // OK type inference
Compiler infer type to use as an argument. 😅
func sumOne(x: Int?) -> Int? {
guard let x = x else {
return nil
}
return x + 1
}
sumOne(x: .some(1)) // OK type inference
sumOne(x: unit(1)) // OK type inference
unit
should be removed completely in the future major release.
I think so too in the future. 👍
Thanks!
The compiler handles the work of type inference each time when an amount of data in context is enough. If it does not, it is not Prelude issue, but a compiler issue that needs to be reported. In a first example let b = .some(2)
will never work since it should be Optional.some(1)
and type of optional will be inferred.
Most of the time unit
used not to initialize values, but to prepare functions for combining, something like values.map(Optional.some)
, in such case type inference is unavoidable.
Also in a Swift 2.3 unit
have almost no value, as now even the following definition is fully legit and does not require any mapping:
let values: [Int] = [1, 2, 3]
let optionalValues: [Int?] = values
@robrix I guess we still need your blessing to merge, even that we theoretically have a button to do so.
I think this is a good change. Thank you!
As suggested in #43
unit
deprecated in honor ofOptional.Some
. Documentation removed. Unit-test removed, to avoid deprecation warning during compilation. I believe it is legit, as there are no guarantees anymore on the workability of deprecated functionality, as well as no plans to support it in future.unit
should be removed completely in the future major release.