Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Eriksen committed Sep 29, 2020
1 parent 15735ac commit 57fc926
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 36 deletions.
99 changes: 98 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
# E.num
# E.num

Swift... but only enums!

## 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)))")
```
35 changes: 0 additions & 35 deletions Sources/E.num/E_num.swift

This file was deleted.

42 changes: 42 additions & 0 deletions Tests/E.numTests/E_numTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
import XCTest
@testable import E_num

internal struct E_num {
var list: Variable = .array(
[
.bool(false),
.string("False"),
.int(0),
.dictionary(
[
.bool(false): .double(3.14)
]
)
]
)

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

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

var stu = Function.void {
print("STFU")
}

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

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

stu()
}
}


final class E_numTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
Expand Down

0 comments on commit 57fc926

Please sign in to comment.