From bf4f06ab4e6ceefe388e0efefcc553526f3d96c2 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 19 Mar 2022 16:34:46 +1100 Subject: more generics --- pkg/cheatsheet/generate.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'pkg/cheatsheet') diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index d88f3d733..ecb75f935 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -13,6 +13,7 @@ import ( "log" "os" + "github.com/jesseduffield/generics/maps" "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/app" "github.com/jesseduffield/lazygit/pkg/config" @@ -174,11 +175,12 @@ outer: bindings []*types.Binding } - groupedBindings := make([]groupedBindingsType, 0, len(contextAndViewBindingMap)) - - for contextAndView, contextBindings := range contextAndViewBindingMap { - groupedBindings = append(groupedBindings, groupedBindingsType{contextAndView: contextAndView, bindings: contextBindings}) - } + groupedBindings := maps.MapToSlice( + contextAndViewBindingMap, + func(contextAndView contextAndViewType, contextBindings []*types.Binding) groupedBindingsType { + return groupedBindingsType{contextAndView: contextAndView, bindings: contextBindings} + }, + ) slices.SortFunc(groupedBindings, func(a, b groupedBindingsType) bool { first := a.contextAndView -- cgit v1.2.3