<commit_before>package library

import (
	"sort"

	"github.com/anaminus/rbxmk"
)

// registry contains registered Libraries.
var registry []rbxmk.Library

// register registers a Library to be returned by All.
func register(library rbxmk.Library) {
	registry = append(registry, library)
}

// All returns a list of Libraries defined in the package, ordered by ascending
// priority.
func All() []rbxmk.Library {
	libs := make([]rbxmk.Library, len(registry))
	copy(libs, registry)
	sort.SliceStable(libs, func(i, j int) bool {
		if libs[i].Priority == libs[j].Priority {
			return libs[i].Name < libs[j].Name
		}
		return libs[i].Priority < libs[j].Priority
	})
	return libs
}
<commit_msg>Refactor library list as sortable type.<commit_after>package library

import (
	"sort"

	"github.com/anaminus/rbxmk"
)

type Libraries []rbxmk.Library

func (l Libraries) Len() int      { return len(l) }
func (l Libraries) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l Libraries) Less(i, j int) bool {
	if l[i].Priority == l[j].Priority {
		return l[i].Name < l[j].Name
	}
	return l[i].Priority < l[j].Priority
}

// registry contains registered Libraries.
var registry Libraries

// register registers a Library to be returned by All.
func register(library rbxmk.Library) {
	registry = append(registry, library)
}

// All returns a list of Libraries defined in the package, ordered by ascending
// priority.
func All() Libraries {
	libs := make(Libraries, len(registry))
	copy(libs, registry)
	sort.Sort(libs)
	return libs
}

{'fraction_non_alphanumeric': 0.1316655694535879, 'fraction_numerical': 0.0, 'mean_word_length': 4.117845117845118, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '561432', 'n_tokens_mistral': 535, 'n_tokens_neox': 518, 'n_words': 158}