replaced nested maps with (map (compose ...) ...)
parent
95824d5f8a
commit
0d7136644a
6
rodo.rkt
6
rodo.rkt
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
(require (prefix-in args: "args.rkt"))
|
(require (prefix-in args: "args.rkt"))
|
||||||
|
|
||||||
(define (main)
|
(define (main args)
|
||||||
(args:check-args (current-command-line-arguments)))
|
(args:check-args args))
|
||||||
|
|
||||||
(main)
|
(main (current-command-line-arguments))
|
||||||
|
|
31
util.rkt
31
util.rkt
|
@ -60,20 +60,11 @@
|
||||||
(string-append lst ". "))
|
(string-append lst ". "))
|
||||||
|
|
||||||
(define (prefix-with-number lst)
|
(define (prefix-with-number lst)
|
||||||
;; Connect the list of numbers to the list of items
|
|
||||||
(map string-append
|
(map string-append
|
||||||
(map prefix-with-period
|
;; Note: compose starts from the last element in it's
|
||||||
;; 3. Convert the numbers made below into strings
|
;; list, as if it were nested, so that would be add1 here
|
||||||
;; so we can append them to other strings
|
(map (compose prefix-with-period number->string add1)
|
||||||
(map number->string
|
(list:range (length lst)))
|
||||||
;; 2. The add1 here makes the numbers more human by
|
|
||||||
;; starting at 1 instead of 0
|
|
||||||
(map add1
|
|
||||||
;; 1. Create a list of numbers from the total
|
|
||||||
;; number of items in a list
|
|
||||||
(list:range (length lst)))))
|
|
||||||
;; This is just the original list that everything will
|
|
||||||
;; be appended to
|
|
||||||
lst))
|
lst))
|
||||||
|
|
||||||
(define (display-prettified-list)
|
(define (display-prettified-list)
|
||||||
|
@ -108,7 +99,6 @@
|
||||||
(display-hash-ref messages:messages 'empty-todo-list)
|
(display-hash-ref messages:messages 'empty-todo-list)
|
||||||
;; If file isn't empty, display a pretty list
|
;; If file isn't empty, display a pretty list
|
||||||
(display-prettified-list))]
|
(display-prettified-list))]
|
||||||
|
|
||||||
;; If file doesn't exist, tell the user
|
;; If file doesn't exist, tell the user
|
||||||
[else
|
[else
|
||||||
(display-hash-ref messages:messages 'file-not-found)
|
(display-hash-ref messages:messages 'file-not-found)
|
||||||
|
@ -134,14 +124,9 @@
|
||||||
(display-hash-ref messages:messages 'try-init))))
|
(display-hash-ref messages:messages 'try-init))))
|
||||||
|
|
||||||
(define (remove-item-from-file args)
|
(define (remove-item-from-file args)
|
||||||
(let ([removed-item (get-removed-item config:path args)]
|
(let* ([removed-item (get-removed-item config:path args)]
|
||||||
;; Todo:
|
[new-list (remove removed-item (file->string-list config:path))])
|
||||||
;; Some how add removed-item here, instead of
|
|
||||||
;; repeating (get-removed-item config:path args).
|
|
||||||
;; This is still a mystery to me
|
|
||||||
[new-list (remove
|
|
||||||
(get-removed-item config:path args)
|
|
||||||
(file->string-list config:path))])
|
|
||||||
(file:display-to-file
|
(file:display-to-file
|
||||||
(string:string-join new-list "\n")
|
(string:string-join new-list "\n")
|
||||||
config:path
|
config:path
|
||||||
|
@ -152,12 +137,10 @@
|
||||||
(define (remove-item args)
|
(define (remove-item args)
|
||||||
(cond [(list-empty? config:path)
|
(cond [(list-empty? config:path)
|
||||||
(display-hash-ref messages:messages 'empty-todo-list)]
|
(display-hash-ref messages:messages 'empty-todo-list)]
|
||||||
|
|
||||||
[(and
|
[(and
|
||||||
(check-for-folder)
|
(check-for-folder)
|
||||||
(check-for-file))
|
(check-for-file))
|
||||||
(remove-item-from-file (vector-ref args 1))]
|
(remove-item-from-file (vector-ref args 1))]
|
||||||
|
|
||||||
[(and (not (check-for-folder)) (not (check-for-file)))
|
[(and (not (check-for-folder)) (not (check-for-file)))
|
||||||
(begin
|
(begin
|
||||||
(display-hash-ref messages:messages 'file-not-found)
|
(display-hash-ref messages:messages 'file-not-found)
|
||||||
|
|
Loading…
Reference in New Issue