Closure

0.1.0

Define and chain Closures with Inputs and Outputs
0xLeif/Closure

What's New

0.1.0

2021-10-05T00:36:53Z

Closure 0.1.0

Define and chain Closures with Inputs and Outputs

Examples

No Scoped State

let noStateCount = Closure<String, String> { text in
  String(repeating: text, count: 4)
}
.then { string in
  Int(string) ?? 0
}


XCTAssertEqual(noStateCount.method("5"), 5555)
XCTAssertEqual(noStateCount.method("5"), 5555)
XCTAssertEqual(noStateCount.method("5"), 5555)

Scoped State

let stateCount: Closure<String, Int> = Closure<String, String> {
  var count = 1
  
  return { text in
    defer {
      count += 1
    }
    
    return String(repeating: text, count: count)
  }
}
.then { string in
  Int(string) ?? 0
}

XCTAssertEqual(stateCount.method("5"), 5)
XCTAssertEqual(stateCount.method("5"), 55)
XCTAssertEqual(stateCount.method("5"), 555)

Closure

Define and chain Closures with Inputs and Outputs

Examples

No Scoped State

let noStateCount = Closure<String, String> { text in
  String(repeating: text, count: 4)
}
.then { string in
  Int(string) ?? 0
}


XCTAssertEqual(noStateCount.method("5"), 5555)
XCTAssertEqual(noStateCount.method("5"), 5555)
XCTAssertEqual(noStateCount.method("5"), 5555)

Scoped State

let stateCount: Closure<String, Int> = Closure<String, String> {
  var count = 1
  
  return { text in
    defer {
      count += 1
    }
    
    return String(repeating: text, count: count)
  }
}
.then { string in
  Int(string) ?? 0
}

XCTAssertEqual(stateCount.method("5"), 5)
XCTAssertEqual(stateCount.method("5"), 55)
XCTAssertEqual(stateCount.method("5"), 555)

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 00:16:08 GMT-0900 (Hawaii-Aleutian Daylight Time)