I had a look at using the Thrush combinator to make more readable the invocation of methods that ask questions. Examples in Clojure but could be any other FP language.
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Using the Thrush combinator to sweeten invocation of methods asking a question
1. What do you think of using the Thrush combinator (Txy=yx) to sweeten the invocation of Clojure methods that ask a question?
(def thrush (fn [x] (fn [y] (y x))))
Which of the following is more readable?
• (palindrome? number)
• (palindromic? number)
• (is-palindrome? number)
• (is-it-a-palindrome? number)
• (are-you-a-palindrome? number)
None are great, right? Calling a method are-you-a-palindrome?
doesn’t look so crazy if you apply Thrush to its argument beforehand:
(let [number (thrush n)]
(number are-you-a-palindrome?))
Defining thrush to be named ‘ask’ looks even more useful:
((ask number) is-it-a-palindrome?)
((ask number) are-you-a-palindrome?)
Thoughts?
Note: there is a parallel with reading the
thread-first macro -> as ‘ask’ in the following:
(-> number (are-you-a-palindrome?))
}
Another example:
None are great, right?
• (name person)
• (name-of person)
• (get-name person)
• (get-name-of person)
• (what-is-its-name? person)
• (what-is-your-name? person)
Using ‘ask’ as an alias for thrush:
((ask person) what-is-its-name?)
((ask person) what-is-your-name?)
@philip_schwarz