From 435ee34acb9d1b2c149b30a38f17a2057be473a5 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 20 Mar 2020 21:42:10 +0100 Subject: [PATCH] utils: Refactor update-graph. Make update-graph follow a little bit more the guidelines here: https://docs.racket-lang.org/style/Choosing_the_Right_Construct.html --- utils.rkt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/utils.rkt b/utils.rkt index 01ef5e4..d6eab79 100644 --- a/utils.rkt +++ b/utils.rkt @@ -277,16 +277,20 @@ ;;; functions. If gr is an weighted graph, the result is a weighted ;;; graph. If gr is an unweighted graph, the result is an unweighted ;;; graph. -(define (update-graph gr #:v-func [v-func identity] #:e-func [e-func identity]) - (let ([edges (for/list ([e (in-edges gr)]) - (match-let ([(list u v) e]) - (if (unweighted-graph? gr) - (list (v-func u) (v-func v)) - (list (e-func (edge-weight gr u v)) - (v-func u) (v-func v)))))]) - (if (unweighted-graph? gr) - (unweighted-graph/directed edges) - (weighted-graph/directed edges)))) +(define (update-graph gr + #:v-func [v-func identity] + #:e-func [e-func identity]) + (define edges + (for/list ([e (in-edges gr)]) + (match-let ([(list u v) e]) + (cond + [(unweighted-graph? gr) (list (v-func u) (v-func v))] + [else (list (e-func (edge-weight gr u v)) + (v-func u) (v-func v))])))) + (cond + [(unweighted-graph? gr) (unweighted-graph/directed edges)] + [else + (weighted-graph/directed edges)])) ;;; ===============