Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chainable

Syntactic sugar for chainable actions over objects

It provides some methods to make creating and working with objects in a functional way.

Any.then

func then(_ block: (inout Self) throws -> Void) rethrows -> Self

For Value types. Allows chained modifications.

struct Obj {
    var a: String
    var b: Int
}

let o = Obj(a: "hola", b: 0)

let c = o.then {
    $0.a = "adios"
}

AnyObject.then

func then(_ block: (Self) throws -> Void) rethrows -> Self

Same as previous but for Reference types. Very useful for in-place initialization.

class VC: UIViewController {

    lazy var button = UIButton().then {
        $0.addTarget(self, action: #selector(action), for: .touchUpInside)
    }
    
    @IBAction
    func action() {
        
    }
}

Any.do

func do(_ block: (Self) throws -> Void) rethrows

Allows terminations actions with objects

Obj(a: "hola", b: 0).then { $0.b = 3 }.do(print)

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages