You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’d like to propose an enhancement to the decimal package. Currently, there are several functions like NewFromInt, NewFromInt64, NewFromUint64, etc., which create a Decimal from different numeric types.
I suggest creating a single function, NewFromNumber, that uses Golang’s generics to handle the creation of a Decimal from any numeric type. This would simplify the API and make it more flexible.
package types
type (
// Natural represents a natural number.// A natural number is a non-negative integer.// {0, 1, 2, 3, ...}Naturalinterface {
~uint|~uint8|~uint16|~uint32|~uint64|~uintptr
}
// Integer represents an integer number.// An integer is a number that can be written without a fractional component.// {..., -2, -1, 0, 1, 2, ...}Integerinterface {
~int|~int8|~int16|~int32|~int64
}
// Float represents a floating-point number.// A floating-point number is a number that has a fractional part.// {..., -0.2, -0.1, 0.0, 0.1, 0.2, ...}Floatinterface {
~float32|~float64
}
// Number represents a number.// A number is a mathematical object used to count, measure, and label.Numberinterface {
Integer|Natural|Float
}
)
package decimal
funcFrom[N types.Number](rawNumberN) Decimal {
// Create a decimal by number type
}
Benefits:
Simplicity: Reduces the number of functions in the API.
Flexibility: Allows for easier extension and usage with any numeric type.
Maintainability: Makes the codebase cleaner and easier to maintain.
Impact:
This change would be backward compatible if the existing functions remain. However, over time, users could migrate to the new, more generic function.
I’m open to feedback and would be happy to contribute a PR if the maintainers agree this is a useful addition.
Thank you for considering this suggestion!
The text was updated successfully, but these errors were encountered:
Hello,
I’d like to propose an enhancement to the decimal package. Currently, there are several functions like NewFromInt, NewFromInt64, NewFromUint64, etc., which create a Decimal from different numeric types.
I suggest creating a single function, NewFromNumber, that uses Golang’s generics to handle the creation of a Decimal from any numeric type. This would simplify the API and make it more flexible.
Example:
Implementation proposal:
Benefits:
Impact:
This change would be backward compatible if the existing functions remain. However, over time, users could migrate to the new, more generic function.
I’m open to feedback and would be happy to contribute a PR if the maintainers agree this is a useful addition.
Thank you for considering this suggestion!
The text was updated successfully, but these errors were encountered: