Merged
Conversation
Introduces a ToInt function to convert various types (int, int32, int64, float32, float64) to int with a fallback value. Includes comprehensive unit tests covering supported and unsupported types.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Pull Request Description
Title:
feature/add-int-operationsMotivation and Improvement
This pull request introduces a new utility function,
ToInt, for converting various types to an integer with a fallback option. The primary motivation behind this change is to streamline and simplify the conversion process of different numeric types and other types to an integer. This enhancement is particularly useful for handling scenarios where input types might vary, providing a consistent and reliable method to obtain an integer value.Changes Made
New Function in
pkg/int/operations.go:ToInt(value any, fallback int) intvalueto an integer. If the conversion is not possible, it returns the providedfallbackvalue.intint32int64float32(truncated to int)float64(truncated to int)Unit Tests in
pkg/int/operations_test.go:ToIntshould handle.int32,int64)float32,float64) ensuring truncationstring,bool,nil) to test fallback behaviorBenefits
This addition enhances the robustness and flexibility of the project by addressing potential type handling issues in a clean and efficient manner.