Skip to content

Commit 688b3e7

Browse files
Copilotjackfirth
andcommitted
Optimize keep-sorted-suggestions: extract shared helper function
Co-authored-by: jackfirth <[email protected]>
1 parent d2935a5 commit 688b3e7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

default-recommendations/keep-sorted-suggestions.rkt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
(require racket/list
13-
racket/sequence
1413
resyntax/base
1514
syntax/parse
1615
syntax/parse/define)
@@ -19,18 +18,20 @@
1918
;@----------------------------------------------------------------------------------------------------
2019

2120

21+
;; Convert an identifier syntax object to its string representation
22+
(define (identifier->string id)
23+
(symbol->string (syntax-e id)))
24+
25+
2226
;; Check if a list of identifiers is sorted alphabetically by their symbol names
2327
(define (identifiers-sorted? ids)
24-
(define id-list (sequence->list ids))
25-
(define id-strings (map (λ (id) (symbol->string (syntax-e id))) id-list))
28+
(define id-strings (map identifier->string ids))
2629
(equal? id-strings (sort id-strings string<?)))
2730

2831

2932
;; Sort a list of syntax objects representing identifiers alphabetically
3033
(define (sort-identifiers ids)
31-
(sort (sequence->list ids)
32-
string<?
33-
#:key (λ (id) (symbol->string (syntax-e id)))))
34+
(sort ids string<? #:key identifier->string))
3435

3536

3637
;; Syntax class for matching a list expression with identifier elements

0 commit comments

Comments
 (0)