Skip to content

Add a generic form of Selection.Map (requiring a more recent Go version) #466

@Fesaa

Description

@Fesaa

Heya!

Was playing around with this in a project, and it has been amazing!

Noticed the Selection.Map only allowing to return a string, so wanted to change that to generics so it could return anything as currently I've used Each every time (and manually putting it in the array), while Map would be nicer to use.

As such the change;

func (s *Selection) Map[T any](f func(int, *Selection) T) (result []T) {
	for i, n := range s.Nodes {
		result = append(result, f(i, newSingleSelection(n, s.document)))
	}

	return result
}

Noticed the project is still on 1.13 when trying to add it myself, so was wondering if there are any plans to update to a newer version to allowed to usage of generics, and other later introduced features.

Thanks for the amazing project! 💕

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions