Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rzane/proc_utils
A set of functional utilities for working with callables in Ruby
https://github.com/rzane/proc_utils
functional-programming ruby
Last synced: about 1 month ago
JSON representation
A set of functional utilities for working with callables in Ruby
- Host: GitHub
- URL: https://github.com/rzane/proc_utils
- Owner: rzane
- License: mit
- Created: 2017-04-05T22:38:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T03:23:52.000Z (almost 8 years ago)
- Last Synced: 2024-11-08T13:05:47.244Z (2 months ago)
- Topics: functional-programming, ruby
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ProcUtils
A set of functional utilities for working with callables in Ruby.
Heavily inspired by [lodash](https://lodash.com/docs).
## Introduction
I love Symbol#to_proc. It just feels good.
```ruby
emails.each(&:deliver)
```However, if your method takes an argument, you need to refactor to use a block.
```ruby
emails.each { |email| email.deliver(:hello) }
```What if you could do this?
```ruby
emails.each(&:deliver.partial(:hello))
```## Installation
Add this line to your application's Gemfile:
```ruby
gem 'proc_utils'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install proc_utils
## Extending Procs
```ruby
require 'proc_utils/core_ext/proc'
```Now, procs will have the following methods:
* partial
* partial_right
* bind
* flip
* wrap
* compose
* memoize
* once## Extending Symbols
```ruby
require 'proc_utils/core_ext/symbol'
```Now, symbols will have the following methods:
* partial
* partial_right
* bind
* memoize
* once## Using without CoreExtensions
I get it, core extensions are scary. Lucky for you, ProcUtils offers pure functions.
For example:
```ruby
func = proc { |name| puts name }
func = ProcUtils.bind(func, 'Rick Flair')
func.call
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/rzane/proc_utils.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).