19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
I'm still a newbie with Clojure, but I already kind of enjoy it.
Disclaimer: may not be "The Clojure Way", I don't know.
(nsday-67-phone-directory(:require[clojure.string:refer[replacesplit-linestrim]]))(defregexps"A map of record fields to regular expressions to match them.
The first capture group is the meaningful part to extract."{:phone#"\+(\d+-\d+-\d+-\d+)":name#"<([^>]+?)>"})(defn-find-first-group"Find `regex` in `book`, then extract the first capture group."[bookregex](->regex(re-findbook)(get1)))(defn-remove-regex"Removes the match of `regex` from `book`."[bookregex](replacebookregex""))(defn-clean"Cleans an `address` into a kinda-human-readable state."[address](->address(replace#"_"" ")(replace#"[^a-zA-Z0-9 .]""")trim))(defn-line->record"Parse a `line` to a book record.
`:address` is the leftover part after extracting phone and name."[line](let[[recordaddress](->>regexpskeys(reduce(fn[[recordrest]key][(assocrecordkey(find-first-grouprest(regexpskey)))(remove-regexrest(regexpskey))])[{}line]))](assocrecord:address(cleanaddress))))(defnphone"Returns information about `number` in `book`, or an error message.
Result depends on how many people with the same `number` were found."[booknumber](let[matching(->>booksplit-lines(mapline->record)(filter#(->>%:phone(=number))))](case(countmatching)0(str"Error => Not found: "number)1(let[record(firstmatching)](format"Phone => %s, Name => %s, Address => %s"(:phonerecord)(:namerecord)(:addressrecord)))(str"Error => Too many people: "number))))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm still a newbie with Clojure, but I already kind of enjoy it.
Disclaimer: may not be "The Clojure Way", I don't know.