Skip to content

Commit

Permalink
Merge pull request #5 from unsplash/conformant-show
Browse files Browse the repository at this point in the history
Make getShow output more conformant
  • Loading branch information
samhh authored Feb 16, 2024
2 parents ef884e9 + 602b10e commit 2a08139
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/modules/index.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const showWeather = getShow<Weather>({
})

assert.strictEqual(showWeather.show(Sun), 'Sun')
assert.strictEqual(showWeather.show(Rain(1)), 'Rain 1')
assert.strictEqual(showWeather.show(Rain(1)), 'Rain(1)')
```

Added in v0.1.0
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const getOrd = <A extends Sum.AnyMember>(ords: Ords<A>): Ord<A> =>
* })
*
* assert.strictEqual(showWeather.show(Sun), 'Sun')
* assert.strictEqual(showWeather.show(Rain(1)), 'Rain 1')
* assert.strictEqual(showWeather.show(Rain(1)), 'Rain(1)')
*
* @since 0.1.0
*/
Expand All @@ -172,9 +172,9 @@ export const getShow = <A extends Sum.AnyMember>(shows: Shows<A>): Show<A> => ({
// defined a member for which the value actually can tangibly be `null`
// e.g. `Member<'Rain', number | null>`.
return k in shows
? `${k} ${(shows[k as keyof typeof shows] as unknown as Show<Value<A>>)
? `${k}(${(shows[k as keyof typeof shows] as unknown as Show<Value<A>>)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.show(v as any)}`
.show(v as any)})`
: k
},
})
4 changes: 2 additions & 2 deletions test/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ describe("index", () => {
})

it("outputs members with values using provived Show instance", () => {
expect(f(A(42))).toBe("A 42")
expect(f(C(42))).toBe("C 24")
expect(f(A(42))).toBe("A(42)")
expect(f(C(42))).toBe("C(24)")
})
})
})

0 comments on commit 2a08139

Please sign in to comment.