Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do returns T #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

do returns T #49

wants to merge 1 commit into from

Conversation

zuccoi
Copy link

@zuccoi zuccoi commented Jun 23, 2017

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
Copy link
Owner

devxoul commented Jun 23, 2017

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

@zuccoi
Copy link
Author

zuccoi commented Jun 23, 2017

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
}

Repository owner deleted a comment from codecov-io Jun 24, 2017
@RomanPodymov
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants