Contents

capnslipp/with

With is a Swift micro-library that provides a with statement, akin to the with functionality found in Python, JavaScript, Visual Basic, Object Pascal, Delphi; using found in C#; and also/let found in Kotlin.

Alternatives

Swift natively supports immediately-called closures, so it's possible to write, for instance, the DateFormatter example above as this without the need for with/withMap:

let dateString = {
	$0.dateStyle = .medium
	$0.timeStyle = .none
	$0.locale = Locale(identifier: "en_US")
	
	let currentDate = Date()
	return $0.string(from: currentDate)
}((DateFormatter()))

However, this puts the operations out of order of how they are executed— the DateFormatter() construction is the last line but happens first, then the closure above it is executed. I prefer With's top-to-bottom ordering stylistically.

Package Metadata

Repository: capnslipp/with

Default branch: master

README: README.md