Skip to content

Commit

Permalink
Add initializer without rawValue argument name. (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw authored Nov 16, 2022
1 parent a375f1f commit 33f44ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Tagged/Tagged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public struct Tagged<Tag, RawValue> {
self.rawValue = rawValue
}

public init(_ rawValue: RawValue) {
self.rawValue = rawValue
}

public func map<B>(_ f: (RawValue) -> B) -> Tagged<Tag, B> {
return .init(rawValue: f(self.rawValue))
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/TaggedTests/TaggedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ enum Tag {}
struct Unit: Error {}

final class TaggedTests: XCTestCase {
func testInit() {
let int1 = Tagged<Self, Int>(rawValue: 42)
let int2 = Tagged<Self, Int>(1729)
XCTAssertNotEqual(int1, int2)
}

func testCustomStringConvertible() {
XCTAssertEqual("1", Tagged<Tag, Int>(rawValue: 1).description)
}
Expand Down

0 comments on commit 33f44ce

Please sign in to comment.