Skip to content

Instantly share code, notes, and snippets.

@mechanicles
Created October 9, 2014 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mechanicles/2d015c1df47ab237e54e to your computer and use it in GitHub Desktop.
Save mechanicles/2d015c1df47ab237e54e to your computer and use it in GitHub Desktop.
Partial Application Example in Ruby.
# 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