E

0.3.0

🟠 Swift Enum Lang
0xLet/E.num

What's New

Variable.array([...]).flatten

2021-03-02T02:26:58Z

Unflattened Variable Output

(lldb) po output
 Variable
   array : 2 elements
     0 : Variable
      - string : "First"
     1 : Variable
       array : 2 elements
        - 0 : E.Variable.void
         1 : Variable
           array : 2 elements
             0 : Variable
               array : 3 elements
                 0 : Variable
                   array : 1 element
                    - 0 : E.Variable.void
                 1 : Variable
                   array : 1 element
                    - 0 : E.Variable.void
                 2 : Variable
                   array : 1 element
                    - 0 : E.Variable.void
             1 : Variable
               array : 2 elements
                 0 : Variable
                  - string : "Link"
                 1 : Variable
                   array : 2 elements
                     0 : Variable
                      - string : "Last"
                     1 : Variable
                       array : 1 element
                         0 : Variable
                          - string : "Last !!!"

Flattened Variable Output

(lldb) po output.flatten
 Variable
   array : 8 elements
     0 : Variable
      - string : "First"
    - 1 : E.Variable.void
    - 2 : E.Variable.void
    - 3 : E.Variable.void
    - 4 : E.Variable.void
     5 : Variable
      - string : "Link"
     6 : Variable
      - string : "Last"
     7 : Variable
      - string : "Last !!!"

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)))")

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Sep 04 2022 00:22:46 GMT-0500 (GMT-05:00)