https://github.com/0xlet/e.num
🟠Swift Enum Lang
https://github.com/0xlet/e.num
enum swift
Last synced: 5 months ago
JSON representation
🟠Swift Enum Lang
- Host: GitHub
- URL: https://github.com/0xlet/e.num
- Owner: 0xLet
- License: mit
- Created: 2020-09-29T13:27:36.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-03T03:29:08.000Z (about 4 years ago)
- Last Synced: 2024-11-20T18:04:49.128Z (6 months ago)
- Topics: enum, swift
- Language: Swift
- Homepage:
- Size: 26.4 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# E
Swift... but only enums!
**[About Swift Enumerations](https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html)**
## Variables
### Basic String Example
```swift
let text: Variable = .string("Hello, World!")
```### Basic Dictionary Example
```swift
let dictionary: Variable = .dictionary(
[
.bool(false): .double(3.14)
]
)
```### Array Example
```swift
let list: Variable = .array(
[
.bool(false),
.string("False"),
.dictionary(
[
.bool(false): .double(3.14)
]
),
.int(27)
]
)
```### Getting Values Example
```swift
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
```swift
let voidExample = Function.void {
print("Print Lorem ipsum")
}
// ...
voidExample()
```### In Function Example
```swift
let printString = Function.in { stringValue in
guard case .string(let value) = stringValue else {
return
}print(value)
}
// ...
printString(.string("Hello, World..."))
```### In & Out Function Example
```swift
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
- [⛓ Chain](https://github.com/0xLeif/Chain)
- [🔠Observation](https://github.com/0xLeif/Observation)