Racket threading macro

8 views
Skip to first unread message

Brian Adkins

unread,
Feb 12, 2016, 1:15:39 PM2/12/16
to TriFunc
I just installed the threading package for Racket, and I'm pretty pleased with the threading macro which provides "pipe"-like functionality. Here are two recent examples:

(define (score word)
  (apply + (~> word
               string-trim
               string-downcase
               string->list
               (map (curry hash-ref points) _))))

(define (word-count str)
  (~> str
      string-downcase
      (string-split #px"[^a-z]+")
      (foldl (λ (word hsh) (hash-update hsh word add1 0))
             (make-immutable-hash)
             _)))


I've been coding up a lot of Racket lately, and pretty much every other day I find another reason to be elated with Racket :)

Brian

Reply all
Reply to author
Forward
0 new messages