Skip to content

Feature: Add ToSliceX for numeric types #325

Description

@shayan-yousefi

I propose adding ToSliceX helper functions to the cast package for converting values into slices of numeric types (e.g. []int, []int64, []float64).

Proposed API

ToIntSlice(i interface{}) []int
ToIntSliceE(i interface{}) ([]int, error)

ToInt64Slice(i interface{}) []int64
ToFloat64Slice(i interface{}) []float64

/* other functions */

These functions would convert common inputs like []interface{}, []string, or already-typed slices.

Benefits

  • Reduces boilerplate
  • Improves consistency with existing cast APIs
  • Makes numeric slice handling simpler and safer

Contribution

I’m happy to implement this feature, including tests and documentation, if the maintainers agree with the approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions