Skip to content

Commit

Permalink
BigDecimal: rename toString to format (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Nov 28, 2023
1 parent accf8a6 commit 9063432
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 100 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-peas-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

BigDecimal: rename `toString` to `format`
14 changes: 7 additions & 7 deletions docs/modules/BigDecimal.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Added in v2.0.0
- [make](#make)
- [unsafeFromString](#unsafefromstring)
- [conversions](#conversions)
- [toString](#tostring)
- [format](#format)
- [unsafeToNumber](#unsafetonumber)
- [guards](#guards)
- [isBigDecimal](#isbigdecimal)
Expand Down Expand Up @@ -172,24 +172,24 @@ Added in v2.0.0

# conversions

## toString
## format

Formats a given `BigDecimal` as a `string`.

**Signature**

```ts
export declare const toString: (n: BigDecimal) => string
export declare const format: (n: BigDecimal) => string
```
**Example**
```ts
import { toString, unsafeFromString } from "effect/BigDecimal"
import { format, unsafeFromString } from "effect/BigDecimal"

assert.deepStrictEqual(toString(unsafeFromString("-5")), "-5")
assert.deepStrictEqual(toString(unsafeFromString("123.456")), "123.456")
assert.deepStrictEqual(toString(unsafeFromString("-0.00000123")), "-0.00000123")
assert.deepStrictEqual(format(unsafeFromString("-5")), "-5")
assert.deepStrictEqual(format(unsafeFromString("123.456")), "123.456")
assert.deepStrictEqual(format(unsafeFromString("-0.00000123")), "-0.00000123")
```

Added in v2.0.0
Expand Down
11 changes: 0 additions & 11 deletions docs/modules/Inspectable.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Added in v2.0.0
- [NodeInspectSymbol (type alias)](#nodeinspectsymbol-type-alias)
- [utils](#utils)
- [toJSON](#tojson)
- [toString](#tostring)

---

Expand Down Expand Up @@ -72,13 +71,3 @@ export declare const toJSON: (x: unknown) => unknown
```
Added in v2.0.0
## toString
**Signature**
```ts
export declare const toString: (x: unknown) => string
```
Added in v2.0.0
14 changes: 7 additions & 7 deletions src/BigDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const BigDecimalProto: Omit<BigDecimal, "value" | "scale" | "normalized"> = {
return isBigDecimal(that) && equals(this, that)
},
toString(this: BigDecimal) {
return toString(this)
return format(this)
},
toJSON(this: BigDecimal) {
return {
Expand Down Expand Up @@ -877,16 +877,16 @@ export const unsafeFromString = (s: string): BigDecimal =>
* @param normalized - The `BigDecimal` to format.
*
* @example
* import { toString, unsafeFromString } from "effect/BigDecimal"
* import { format, unsafeFromString } from "effect/BigDecimal"
*
* assert.deepStrictEqual(toString(unsafeFromString("-5")), "-5")
* assert.deepStrictEqual(toString(unsafeFromString("123.456")), "123.456")
* assert.deepStrictEqual(toString(unsafeFromString("-0.00000123")), "-0.00000123")
* assert.deepStrictEqual(format(unsafeFromString("-5")), "-5")
* assert.deepStrictEqual(format(unsafeFromString("123.456")), "123.456")
* assert.deepStrictEqual(format(unsafeFromString("-0.00000123")), "-0.00000123")
*
* @since 2.0.0
* @category conversions
*/
export const toString = (n: BigDecimal): string => {
export const format = (n: BigDecimal): string => {
const negative = n.value < bigint0
const absolute = negative ? `${n.value}`.substring(1) : `${n.value}`

Expand Down Expand Up @@ -927,7 +927,7 @@ export const toString = (n: BigDecimal): string => {
* @since 2.0.0
* @category conversions
*/
export const unsafeToNumber = (n: BigDecimal): number => Number(toString(n))
export const unsafeToNumber = (n: BigDecimal): number => Number(format(n))

/**
* Checks if a given `BigDecimal` is an integer.
Expand Down
4 changes: 2 additions & 2 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Equivalence from "./Equivalence.js"
import { dual, identity, pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import type { TypeLambda } from "./HKT.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { NonEmptyIterable } from "./NonEmptyIterable.js"
import type { Option } from "./Option.js"
import * as O from "./Option.js"
Expand Down Expand Up @@ -127,7 +127,7 @@ const ChunkProto: Omit<Chunk<unknown>, "backing" | "depth" | "left" | "length" |
_A: (_: never) => _
},
toString<A>(this: Chunk<A>) {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON<A>(this: Chunk<A>) {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/Duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type * as equivalence from "./Equivalence.js"
import { dual } from "./Function.js"
import * as Hash from "./Hash.js"
import type { Inspectable } from "./Inspectable.js"
import { NodeInspectSymbol, toString } from "./Inspectable.js"
import { format, NodeInspectSymbol } from "./Inspectable.js"
import * as Option from "./Option.js"
import * as order from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -123,7 +123,7 @@ const DurationProto: Omit<Duration, "value"> = {
return isDuration(that) && equals(this, that)
},
toString(this: Duration) {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON(this: Duration) {
switch (this.value._tag) {
Expand Down
6 changes: 2 additions & 4 deletions src/Inspectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,5 @@ export const toJSON = (x: unknown): unknown => {
return x
}

/**
* @since 2.0.0
*/
export const toString = (x: unknown): string => JSON.stringify(x, null, 2)
/** @internal */
export const format = (x: unknown): string => JSON.stringify(x, null, 2)
6 changes: 3 additions & 3 deletions src/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as Equal from "./Equal.js"
import * as Equivalence from "./Equivalence.js"
import { dual, identity, unsafeCoerce } from "./Function.js"
import * as Hash from "./Hash.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -99,7 +99,7 @@ const ConsProto: Omit<Cons<unknown>, "head" | "tail"> = {
[TypeId]: TypeId,
_tag: "Cons",
toString(this: Cons<unknown>) {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON(this: Cons<unknown>) {
return {
Expand Down Expand Up @@ -165,7 +165,7 @@ const NilProto: Nil<unknown> = {
[TypeId]: TypeId,
_tag: "Nil",
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/MutableHashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as Dual from "./Function.js"
import * as HashMap from "./HashMap.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as MutableRef from "./MutableRef.js"
import * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -34,7 +34,7 @@ const MutableHashMapProto: Omit<MutableHashMap<unknown, unknown>, "backingMap">
return this.backingMap.current[Symbol.iterator]()
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/MutableHashSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @since 2.0.0
*/
import * as Dual from "./Function.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as MutableHashMap from "./MutableHashMap.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -32,7 +32,7 @@ const MutableHashSetProto: Omit<MutableHashSet<unknown>, "keyMap"> = {
return Array.from(this.keyMap).map(([_]) => _)[Symbol.iterator]()
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/MutableList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @since 2.0.0
*/
import * as Dual from "./Function.js"
import { NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Inspectable } from "./Inspectable.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -55,7 +55,7 @@ const MutableListProto: Omit<MutableList<unknown>, "head" | "tail"> = {
}
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/MutableQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as Chunk from "./Chunk.js"
import * as Dual from "./Function.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as MutableList from "./MutableList.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -51,7 +51,7 @@ const MutableQueueProto: Omit<MutableQueue<unknown>, "queue" | "capacity"> = {
return Array.from(this.queue)[Symbol.iterator]()
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/MutableRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as Equal from "./Equal.js"
import * as Dual from "./Function.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"

Expand All @@ -29,7 +29,7 @@ export interface MutableRef<out T> extends Pipeable, Inspectable {
const MutableRefProto: Omit<MutableRef<unknown>, "current"> = {
[TypeId]: TypeId,
toString<A>(this: MutableRef<A>): string {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON<A>(this: MutableRef<A>) {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/SortedMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Equal from "./Equal.js"
import * as Dual from "./Function.js"
import { pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import { type Inspectable, NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as Option from "./Option.js"
import type { Order } from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -50,7 +50,7 @@ const SortedMapProto: Omit<SortedMap<unknown, unknown>, "tree"> = {
return this.tree[Symbol.iterator]()
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/SortedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Dual from "./Function.js"
import { pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import type { Inspectable } from "./Inspectable.js"
import { NodeInspectSymbol, toJSON, toString } from "./Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Order } from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -49,7 +49,7 @@ const SortedSetProto: Omit<SortedSet<unknown>, "keyTree"> = {
return RBT.keys(this.keyTree)
},
toString<A>(this: SortedSet<A>) {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON() {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/internal/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Equal from "../Equal.js"
import { dual } from "../Function.js"
import { globalValue } from "../GlobalValue.js"
import * as Hash from "../Hash.js"
import { NodeInspectSymbol, toJSON, toString } from "../Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "../Inspectable.js"
import type * as O from "../Option.js"
import { pipeArguments } from "../Pipeable.js"
import { hasProperty } from "../Predicate.js"
Expand Down Expand Up @@ -33,7 +33,7 @@ export const TagProto: C.Tag<unknown, unknown> = {
_Identifier: (_: unknown) => _
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON<I, A>(this: C.Tag<I, A>) {
return {
Expand Down Expand Up @@ -108,7 +108,7 @@ export const ContextProto: Omit<C.Context<unknown>, "unsafeMap"> = {
return pipeArguments(this, arguments)
},
toString() {
return toString(this.toJSON())
return format(this.toJSON())
},
toJSON<A>(this: C.Context<A>) {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { globalValue } from "../GlobalValue.js"
import * as Hash from "../Hash.js"
import * as HashMap from "../HashMap.js"
import * as HashSet from "../HashSet.js"
import { NodeInspectSymbol, toJSON, toString } from "../Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "../Inspectable.js"
import * as List from "../List.js"
import type * as LogLevel from "../LogLevel.js"
import type * as LogSpan from "../LogSpan.js"
Expand Down Expand Up @@ -172,7 +172,7 @@ class EffectPrimitive {
}
}
toString() {
return toString(this.toJSON())
return format(this.toJSON())
}
[NodeInspectSymbol]() {
return this.toJSON()
Expand Down Expand Up @@ -210,7 +210,7 @@ class EffectPrimitiveFailure {
}
}
toString() {
return toString(this.toJSON())
return format(this.toJSON())
}
[NodeInspectSymbol]() {
return this.toJSON()
Expand Down Expand Up @@ -248,7 +248,7 @@ class EffectPrimitiveSuccess {
}
}
toString() {
return toString(this.toJSON())
return format(this.toJSON())
}
[NodeInspectSymbol]() {
return this.toJSON()
Expand Down
4 changes: 2 additions & 2 deletions src/internal/either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type * as Either from "../Either.js"
import * as Equal from "../Equal.js"
import { dual } from "../Function.js"
import * as Hash from "../Hash.js"
import { NodeInspectSymbol, toJSON, toString } from "../Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "../Inspectable.js"
import type { Option } from "../Option.js"
import { hasProperty } from "../Predicate.js"
import { EffectPrototype } from "./effectable.js"
Expand All @@ -26,7 +26,7 @@ const CommonProto = {
return this.toJSON()
},
toString<E, A>(this: Either.Left<E, A>) {
return toString(this.toJSON())
return format(this.toJSON())
}
}

Expand Down
Loading

0 comments on commit 9063432

Please sign in to comment.