remove 'case-lambdas'

pull/3/head
Matthew Butterick 10 years ago
parent 293defb2d9
commit bc37761543

@ -27,14 +27,10 @@
(reverse (cons (reverse last-list) list-of-lists)))
(define/typed+provide slicef-at
(define/typed+provide (slicef-at xs pred [force? #f])
;; with polymorphic function, use cased typing to simulate optional position arguments
(All (A) (case-> ((Listof A) (A -> Boolean) -> (Listof (Listof A)))
((Listof A) (A -> Boolean) Boolean -> (Listof (Listof A)))))
(case-lambda
[(xs pred)
(slicef-at xs pred #f)]
[(xs pred force?)
(define-values (last-list list-of-lists)
(for/fold:
([current-list : (Listof A) empty][list-of-lists : (Listof (Listof A)) empty])
@ -49,7 +45,7 @@
(cons (reverse last-list) list-of-lists)))])
(if (and force? (not (empty? list-of-lists)) (not (pred (caar list-of-lists))))
(cdr list-of-lists)
list-of-lists))]))
list-of-lists)))
(define/typed+provide (slicef-after xs pred)
(All (A) ((Listof A) (A -> Boolean) -> (Listof (Listof A))))
@ -64,14 +60,10 @@
(cons (reverse last-list) list-of-lists))))
(define/typed+provide slice-at
(define/typed+provide (slice-at xs len [force? #f])
;; with polymorphic function, use cased typing to simulate optional position arguments
(All (A) (case-> ((Listof A) Positive-Integer -> (Listof (Listof A)))
((Listof A) Positive-Integer Boolean -> (Listof (Listof A)))))
(case-lambda
[(xs len)
(slice-at xs len #f)]
[(xs len force?)
(define-values (last-list list-of-lists)
(for/fold: ([current-list : (Listof A) empty][list-of-lists : (Listof (Listof A)) empty])
([x (in-list xs)][i (in-naturals)])
@ -80,7 +72,7 @@
(values (cons x current-list) list-of-lists))))
(reverse (if (or (empty? last-list) (and force? (not (= len (length last-list)))))
list-of-lists
(cons (reverse last-list) list-of-lists)))]))
(cons (reverse last-list) list-of-lists))))
(define/typed+provide (filter-split xs pred)
@ -165,16 +157,10 @@
(cons tail (loop head (cdr bps)))))))))
(define/typed+provide shift
(define/typed+provide (shift xs how-far [fill-item #f] [cycle #f])
(All (A) (case-> ((Listof (Option A)) Integer -> (Listof (Option A)))
((Listof (Option A)) Integer (Option A) -> (Listof (Option A)))
((Listof (Option A)) Integer (Option A) Boolean -> (Listof (Option A)))))
(case-lambda
[(xs how-far)
(shift xs how-far #f #f)]
[(xs how-far fill-item)
(shift xs how-far fill-item #f)]
[(xs how-far fill-item cycle)
(define abs-how-far (abs how-far))
(cond
[(> abs-how-far (length xs)) (error 'shift "index is too large for list\nindex: ~a\nlist: ~v" how-far xs)]
@ -188,17 +174,11 @@
(define filler (if cycle
(take xs abs-how-far)
(make-list abs-how-far fill-item)))
(append (drop xs abs-how-far) filler)])]))
(append (drop xs abs-how-far) filler)]))
(define/typed+provide shifts
(define/typed+provide (shifts xs how-fars [fill-item #f] [cycle #f])
(All (A) (case-> ((Listof (Option A)) (Listof Integer) -> (Listof (Listof (Option A))))
((Listof (Option A)) (Listof Integer) (Option A) -> (Listof (Listof (Option A))))
((Listof (Option A)) (Listof Integer) (Option A) Boolean -> (Listof (Listof (Option A))))))
(case-lambda
[(xs how-fars)
(shifts xs how-fars #f #f)]
[(xs how-fars fill-item)
(shifts xs how-fars fill-item #f)]
[(xs how-fars fill-item cycle)
(map (λ:([how-far : Integer]) (shift xs how-far fill-item cycle)) how-fars)]))
(map (λ:([how-far : Integer]) (shift xs how-far fill-item cycle)) how-fars))

Loading…
Cancel
Save