Go to file
Zach Eriksen 41d79fca23
Update README.md
2021-03-02 21:29:08 -06:00
.github/workflows Create swift.yml 2020-10-31 15:13:06 -05:00
Sources/E Formatting 2021-03-01 20:21:12 -06:00
Tests Added cyclic state 2020-10-31 14:48:43 -05:00
.gitignore POC E.num 2020-09-29 08:31:55 -05:00
LICENSE Initial commit 2020-09-29 08:27:37 -05:00
Package.swift Change E.num to E for SPM 2020-09-29 14:56:26 -05:00
README.md Update README.md 2021-03-02 21:29:08 -06:00

README.md

E

Swift... but only enums!

About Swift Enumerations

Variables

Basic String Example

let text: Variable = .string("Hello, World!")

Basic Dictionary Example

let dictionary: Variable = .dictionary(
	[
		.bool(false): .double(3.14)
	]
)

Array Example

let list: Variable = .array(
	[
		.bool(false),
		.string("False"),
		.dictionary(
			[
				.bool(false): .double(3.14)
			]
		),
		.int(27)
	]
)

Getting Values Example

if case .string(let value) = text {
	print("String: \(value)")
}

if case .array(let value) = list,
   let lastValue = value.last,
   case .int(let number) = lastValue {
	print(number * 99)
}

Functions

Void Function Example

let voidExample = Function.void {
	print("Print Lorem ipsum")
}
// ...
voidExample()

In Function Example

let printString = Function.in { stringValue in
	guard case .string(let value) = stringValue else {
		return
	}

	print(value)
}
// ...
printString(.string("Hello, World..."))

In & Out Function Example

let double = Function.inout { value in
	if case .int(let value) = value {
		return .int(value * 2)
	} else if case .float(let value) = value {
		return .float(value * 2)
	} else if case .double(let value) = value {
		return .double(value * 2)
	} else if case .string(let value) = value {
		return .string("\(value)\(value)")
	}

	return .array([value, value])
}
// ...
print("Double of \(Variable.float(3.14)) is \(double(.float(3.14)))")

Projects using E.num