{"id":15608913,"url":"https://github.com/serradura/ruby-lambdas","last_synced_at":"2025-04-28T11:46:51.515Z","repository":{"id":56893553,"uuid":"163464040","full_name":"serradura/ruby-lambdas","owner":"serradura","description":"Expose Ruby object methods as lambdas (functions).","archived":false,"fork":false,"pushed_at":"2020-02-29T15:08:32.000Z","size":47,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T01:47:40.278Z","etag":null,"topics":["curried-functions","functional-programming","lambdas","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/ruby-lambdas","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serradura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-29T01:33:48.000Z","updated_at":"2022-08-13T11:54:33.000Z","dependencies_parsed_at":"2022-08-20T16:10:37.965Z","dependency_job_id":null,"html_url":"https://github.com/serradura/ruby-lambdas","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serradura%2Fruby-lambdas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serradura%2Fruby-lambdas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serradura%2Fruby-lambdas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serradura%2Fruby-lambdas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serradura","download_url":"https://codeload.github.com/serradura/ruby-lambdas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251309484,"owners_count":21568828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curried-functions","functional-programming","lambdas","ruby","ruby-gem"],"created_at":"2024-10-03T05:40:28.774Z","updated_at":"2025-04-28T11:46:51.474Z","avatar_url":"https://github.com/serradura.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maintainability](https://api.codeclimate.com/v1/badges/8ce742227db2f760463e/maintainability)](https://codeclimate.com/github/serradura/ruby-lambdas/maintainability)\n\n# RubyLambdas\n\nExpose Ruby object methods as lambdas (functions).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ruby-lambdas', require: 'ruby/lambdas'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ruby-lambdas\n\n## Usage\n\n**Basics:**\n```ruby\nrequire \"ruby/lambdas\"\n\nStrings::Strip.call(\" hello \") # =\u003e \"hello\"\n\n# Strings::Trim is an alias to the Strings::Strip function\nStrings::Trim.call(\" hello \") # =\u003e \"hello\"\n\n# Other ways to call a lambda (function):\nStrings::Trim[\" hello \"]\nStrings::Trim.(\" hello \")    # Syntactic sugar to hide “call”.\nStrings::Trim.===(\" hello \") # This allows a proc object to be the target of a when clause in a case statement.\nStrings::Trim.yield(\" hello \")\n```\n\n**Partial application (curried functions):**\n\n```ruby\nrequire \"ruby/lambdas\"\n\n# We call a function with fewer arguments than it expects and It returns a\n# function that takes the remaining arguments.\n# And this is called Partial Application of Functions. e.g:\n\nStrings::GSub.call(/[aeiou]/, \"hello\", \"*\")           # =\u003e \"h*ll*\"\nStrings::GSub.call(/[aeiou]/).call(\"hello\", \"*\")      # =\u003e \"h*ll*\"\nStrings::GSub.call(/[aeiou]/).call(\"hello\").call(\"*\") # =\u003e \"h*ll*\"\n\n# Last example with an alternative syntax:\nStrings::GSub.(/[aeiou]/).(\"hello\").(\"*\") # =\u003e \"h*ll*\"\n\n# ---\n\nreplace_vowels = Strings::GSub.call(/[aeiou]/)\n\nreplace_vowels.call(\"_\", \"banana\") # =\u003e \"b_n_n_\"\n\n# ---\n\nhide_vowels = replace_vowels.call(\"*\")\n\nhide_vowels.call(\"hello\") # =\u003e \"h*ll*\"\n```\n\n**Pipelines:**\n\n```ruby\nrequire \"ruby/lambdas\"\n\n###########################\n# RUBY_VERSION \u003e= '2.6.0' #\n###########################\n\nvalue = ' I WILL be a url slug   '\n\nvalue\n  .then(\u0026Strings::Strip)\n  .then(\u0026Strings::Downcase)\n  .then(\u0026Strings::GSub[' ', '-'])\n\n# =\u003e \"i-will-be-a-url-slug\"\n\n###########################\n# RUBY_VERSION \u003e= '2.5.0' #\n###########################\n\nvalue = ' I WILL be a url slug   '\n\nvalue\n  .yield_self(\u0026Strings::Strip)\n  .yield_self(\u0026Strings::Downcase)\n  .yield_self(\u0026Strings::GSub[' ', '-'])\n\n# =\u003e \"i-will-be-a-url-slug\"\n```\n\n**Composing functions (`RUBY_VERSION \u003e= '2.6.0'`):**\n```ruby\nrequire \"ruby/lambdas\"\n                                # -- Alternative syntax --\nSlugify =                       # Slugify =\n  Strings::FromObject           #   Strings::String\n    .\u003e\u003e Strings::Strip          #     \u003e\u003e Strings::Trim      \\\n    .\u003e\u003e Strings::Downcase       #     \u003e\u003e Strings::LowerCase \\\n    .\u003e\u003e Strings::GSub[' ', '-'] #     \u003e\u003e Strings::ReplaceAll[' ', '-']\n\n# Reading the previous composition (Step by step):\n#   1. Convert a given object (first input) as a String\n#   2. Remove all whitespaces from both sides of a string.\n#   3. Convert a string to all lower case.\n#   4. Replace all occurrences of \" \" by \"-\".\n\n#########\n# Usage #\n#########\nSlugify.(nil)                        # =\u003e \"\"\nSlugify.(1)                          # =\u003e \"1\"\nSlugify.(1.0)                        # =\u003e \"1.0\"\nSlugify.(' I WILL be a url slug   ') # =\u003e \"i-will-be-a-url-slug\"\n```\n\n### Strict mode\n\nBy default, all functions believe in their given inputs data types. To change this behavior, you can enable the strict mode (data type checking) via `require \"ruby/lambdas/strict-mode\"`. e.g:\n\n```ruby\np [\"2\", \"4\"].map(\u0026Numerics + \"1\") # =\u003e [\"12\", \"14\"]\n\nrequire \"ruby/lambdas/strict-mode\"\n\np [\"2\", \"4\"].map(\u0026Numerics + \"1\") # =\u003e Numerics::TypeError (\"1\" must be Numeric)\np [\"2\", \"4\"].map(\u0026Numerics + 1)   # =\u003e Numerics::TypeError (\"2\" must be Numeric)\np [2, \"4\"].map(\u0026Numerics + 1)     # =\u003e Numerics::TypeError (\"4\" must be Numeric)\np [2, 4].map(\u0026Numerics + 1)       # =\u003e [3, 5]\n```\n\n### Do you like it?\n\nSo, look in [examples folder](https://github.com/serradura/ruby-lambdas/tree/master/examples) to see more ideas and benchmarks.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/serradura/ruby-lambdas. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the RubyLambdas project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serradura/ruby-lambdas/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserradura%2Fruby-lambdas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserradura%2Fruby-lambdas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserradura%2Fruby-lambdas/lists"}