Contents

brunogama/ClosureDecorator

ClosureDecorator

Usage

Sample 1


let operation: (Int, Int) -> Int = { $0 + $1 }

let decoratedOperation = ClosureDecorator.decorate(operation) { closure, valueA, valueB in
    let injectedValueA = valueA + 1
    let injectedValueB = valueB + 1
    
    return closure(injectedValueA, injectedValueB)
}

let result = decoratedOperation(1, 2)

print("Result: \(result)") // Prints 5

Sample 2

struct EquatableTypeHandler {
    let canHandle: (Any, Any) -> Bool
    let areEqual: (Any, Any) -> Bool

    init(
        canHandle: @escaping (Any, Any) -> Bool,
        areEqual: @escaping (Any, Any) -> Bool
    ) {
        self.canHandle = ClosureDecorator.decorate(canHandle) { closure, a, b in
            print("🚨 Checking if can handle ")
            // Perform more stuff 
            return closure(a, b)
        }

        self.areEqual = ClosureDecorator.decorate(canHandle) { closure, a, b in
            print("🚨 Checking if are equal ")
            // Perform more stuff 
            return closure(a, b)
        }
    }
}

Package Metadata

Repository: brunogama/ClosureDecorator

Stars: 1

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

Topics: memory-management, object-oriented-programming, objective-c, security, swift, swiftui

README: README.md