Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce #15

Merged
merged 4 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Tagged/Tagged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,10 @@ extension Tagged: SignedNumeric where RawValue: SignedNumeric {
// self.init(rawValue: f(elements))
// }
//}

// MARK: - Coerce
extension Tagged {
public func coerce<Tag2>() -> Tagged<Tag2, RawValue> {
return unsafeBitCast(self, to: Tagged<Tag2, RawValue>.self)
}
}
9 changes: 9 additions & 0 deletions Tests/TaggedTests/TaggedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ final class TaggedTests: XCTestCase {
XCTAssertEqual(containers.first?.id.rawValue, nil)
}())
}

func testCoerce() {
let x: Tagged<Tag, Int> = 1

enum Tag2 {}
let x2: Tagged<Tag2, Int> = x.coerce()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also looks like there is some weird spacing here. we use 2 space tabs.


XCTAssertEqual(1, x2.rawValue)
}
}