What is EasyClosure?
EasyClosure is a powerful library for working with closures in Swift. It aims to simplify the usage and management of closures, allowing developers to write cleaner and more concise code.
Features
- EasyClosure simplifies the syntax for creating closures.
- Provides a set of utility functions for working with closures.
- Offers convenient shorthand notations for common closure operations.
- Allows developers to easily manage strong reference cycles.
- Enables the creation of expressive and functional programming patterns.
Installation
You can install EasyClosure using Swift Package Manager (SPM). Simply add the following dependency to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/easyclosure/EasyClosure.git", from: "1.0.0")
]
Usage
Using EasyClosure is straightforward. After importing the library, you can start leveraging its features. Below are some examples:
Closure Creation
EasyClosure provides a simplified syntax for creating closures:
// Original syntax
let closure1 = { (param: Int) -> String in
return "This is a closure with \(param)"
}
// EasyClosure syntax
let closure2 = EC.closure { (param: Int) -> String in
return "This is a closure with \(param)"
}
Closure Invocation
You can invoke a closure using the shorthand invoke
method:
let closure = EC.closure { (param: Int) -> String in
return "This closure was invoked with \(param)"
}
let result = closure.invoke(with: 5)
Closure Chaining
EasyClosure allows chaining multiple closures together:.
let firstClosure = EC.closure { (param: Int) -> Int in
return param * 2
}
let secondClosure = EC.closure { (param: Int) -> String in
return "Result: \(param)"
}
let composedClosure = firstClosure.chain(with: secondClosure)
let result = composedClosure.invoke(with: 5)
Contributing
We welcome contributions to the EasyClosure project. To contribute, follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
License
EasyClosure is released under the MIT License. See the LICENSE file for more details.