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

自定义操作符,展开嵌套的神器可以解释一下吗? #6

Open
YoShen opened this issue Jan 15, 2016 · 1 comment
Open

自定义操作符,展开嵌套的神器可以解释一下吗? #6

YoShen opened this issue Jan 15, 2016 · 1 comment

Comments

@YoShen
Copy link

YoShen commented Jan 15, 2016

我看到翁阳的Swift改善既有代码的设计中得自定义操作符,这一部分看不懂,可以解释下吗?

@harryzjm
Copy link

这样子应该好理解一些

func |>(lhs: AsyncTask, rhs: Action) -> AsyncTask {
    return { (action: Action) in
        let block: Action = {
            rhs()
            action()
        }
        lhs(block)
    }
}

func |>(lhs: AsyncTask, rhs: Action) -> Action {
    return {
        lhs( rhs )
    }
}

func |>(lhs: AsyncTask, rhs: AsyncTask) -> AsyncTask {
    return { (action: Action) in
        let block: Action = {
            rhs( action )
        }
        lhs(block)
    }
}

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

No branches or pull requests

2 participants