https://github.com/vergegroup/swift-operator-wrap
`&>` A tiny library that enables us to describe operations in method-chain.
https://github.com/vergegroup/swift-operator-wrap
swift
Last synced: 26 days ago
JSON representation
`&>` A tiny library that enables us to describe operations in method-chain.
- Host: GitHub
- URL: https://github.com/vergegroup/swift-operator-wrap
- Owner: VergeGroup
- License: mit
- Created: 2020-12-28T07:41:20.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-31T20:33:25.000Z (9 months ago)
- Last Synced: 2025-07-02T17:45:14.296Z (6 months ago)
- Topics: swift
- Language: Swift
- Homepage:
- Size: 25.4 KB
- Stars: 15
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# value`&>`.do { ... }
A tiny library that enables us to describe operations in method-chain.
## Usage
```swift
let result: String = ""&>.map { Int($0) }&>.do { print($0 as Any) }
let value: String? = ""&>.filter { !$0.isEmpty }
let view: UIView = UIView()&>.do {
$0.backgroundColor = .white
}
```
```swift
let someProperty = await fetch()&>.map { data in
data.someProperty
}
```
## Motivation
Actually, I'm not addicted to getting a custom operator.
However **a global function** or **operator** are the only way to add a new feature without customizing our own types.
Another way is using something protocol and extending it like this.
It can not be used in struct without adding that protocol.
In fact, this structure looks very natural, because the all of method chaining in Swift standard libary come from an kind of monad.
Like, `Optional`, `Array` and `Dictionary`.
And this keeps Swift clean code base at the beginning.
You have no methods at you declared a struct!