devxoul / Then

✨ Super sweet syntactic sugar for Swift initializers
MIT License
4.18k stars 290 forks source link

`do` returns T #49

Open zuccoi opened 7 years ago

zuccoi commented 7 years ago

I want do to return arbitrary value. When you don't return anything in block of do, it's usage is same as before.

devxoul commented 7 years ago

Use then instead if you'd like to use such like that :-)

zuccoi commented 7 years ago

then's primary use case is to customize newly created instance. So, then returns the instance of type Self.

On the other hand, do is not restricted to Self. do can return nothing, and instance with type of T (arbitrary type).

If you allow do to return T, you can do something like below

let firstDateOfNextMonth: Date = Calendar(identifier: .gregorian).do {
  var date = $0.date(bySetting: .day, value: 1, of: Date())!
  date = $0.date(byAdding: .month, value: 1, to: date)!
  return date
}
RomanPodymov commented 3 years ago

Hello @zuccoi Do you still want to merge this pull request?