Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slice): add SplitBy function to split slices based on an iteratee #434

Closed
wants to merge 1 commit into from
Closed

feat(slice): add SplitBy function to split slices based on an iteratee #434

wants to merge 1 commit into from

Conversation

kilianpaquier
Copy link

Purpose

Add SplitBy(collection []T, predicate func(item T, index int) bool) ([]T, []T) to slice.go features.

A little more intuitive than PartitionBy when trying to split a slice in two slices.

@samber
Copy link
Owner

samber commented Jun 27, 2024

Some people might want to split in 3 lists, 4 lists, 5 lists...

I suppose a PartitionBy[T, bool](...) map[bool][]T would be simpler.

@kilianpaquier
Copy link
Author

Hi @samber, right, it would allow to have multiple partitions while having a better accessibility than:

p1 := partitions[0]
p2 := partitions[1]

But PartitionBy is already used, could SplitBy still be acceptable ? Or do you have a better name in mind ?

@kilianpaquier
Copy link
Author

GroupBy should do the job with this point of view !

@kilianpaquier kilianpaquier deleted the dev/kpaquier/split-by branch June 27, 2024 20:38
@samber
Copy link
Owner

samber commented Jun 28, 2024

You can use lo.FilterReject that does a similar job.

@samber samber mentioned this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants