Skip to content

[v2] ChunkString behavior inconsistency with Chunk for empty input #788

@d-enk

Description

@d-enk

Description

ChunkString and Chunk have inconsistent behavior when handling empty inputs:

  • Chunk([]rune{}, 1) returns [] (empty slice)
  • ChunkString("", 1) returns [""] (slice with one empty string)

Expected Behavior

Both functions should return empty collections for empty inputs. ChunkString("", 1) should return [] for consistency with Chunk.

Actual Behavior

playground

package main

import (
	"fmt"

	"github.com/samber/lo"
)

func main() {
	// Chunk returns empty slice
	fmt.Printf("Chunk([]rune{}, 1) = %q\n", lo.Chunk([]rune{}, 1))
	// Output: Chunk([]rune{}, 1) = []

	// ChunkString returns slice with empty string
	fmt.Printf(`ChunkString("", 1) = %q`, lo.ChunkString("", 1))
	// Output: ChunkString("", 1) = [""]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeIntroduces changes that break backward compatibility or alter the public API.bugSomething isn't working as expected

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions