Skip to content

it.WithoutNth unnecessarily restricts T to comparable (inconsistent with lo.WithoutNth) #959

Description

@deepakganesh78

Description

it.WithoutNth uses T comparable type constraint, but lo.WithoutNth correctly uses T any.

Since WithoutNth only operates on indices (nths ...int), it never compares T values, so the comparable constraint is unnecessarily restrictive and prevents using it.WithoutNth with non-comparable types (e.g., slices, maps, funcs).

Additionally, docs/data/core-withoutnth.md shows T comparable in the signature, which doesn't match the actual lo.WithoutNth code that uses T any.

Expected Behavior

it.WithoutNth should use T any to match lo.WithoutNth and allow non-comparable types.

Actual Behavior

it.WithoutNth requires T comparable, so code like this fails to compile:

go seq := slices.Values([][]int{{1, 2}, {3, 4}, {5, 6}}) result := slices.Collect(it.WithoutNth(seq, 1)) // compile error: []int does not satisfy comparable

Root Cause

it.WithoutNth calls RejectI (which uses T any) and lo.Keyify on nths ([]int). Neither requires T to be comparable. The constraint appears to have been copied from it.Without (which does need comparable).

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