Skip to content

inamiy/Swift-Union

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift-Union

Poor man's untagged union type in Swift.

func testUnion_first() throws {
    @Union<Int, String>
    var union = 1

    XCTAssertEqual($union.value(of: Int.self), 1)
    XCTAssertEqual($union.value(of: String.self), nil)
}

func testUnion_second() throws {
    @Union<Int, String>
    var union = "hello"

    XCTAssertEqual($union.value(of: String.self), "hello")
    XCTAssertEqual($union.value(of: Int.self), nil)
}

func testUnion3() throws {
    @Union3<Int, String, Bool>
    var union = true

    XCTAssertEqual($union.value(of: Bool.self), true)
}

See also: inamiy/Swift-Intersection

About

Poor man's untagged union type in Swift.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages