Created
October 9, 2014 17:15
-
-
Save mechanicles/2d015c1df47ab237e54e to your computer and use it in GitHub Desktop.
Partial Application Example in Ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Partial Application Example in Ruby | |
# We have this string 'all mimsy were the borogoves' and we need to convert this | |
# string into another string and it contains 3 characters or less than 3 | |
# characters of words. | |
split = -> (string) { | |
string.split(' ') | |
} | |
capitalize = -> (words_array) { | |
words_array.map(&:capitalize) | |
} | |
filter = -> (capitalized_words) { | |
capitalized_words.select do |w| | |
w.length <= 3 | |
end | |
} | |
join = -> (filtered_words) { | |
filtered_words.join(" ") | |
} | |
split_capitalize_filter_join = -> (string) { | |
join.(filter.(capitalize.(split.(string)))) | |
} | |
puts split_capitalize_filter_join.('all mimsy were the borogoves') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment