Project

proc_utils

0.0
No commit activity in last 3 years
No release in over 3 years
A set of functional utilities for working with callables.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.14
~> 5.0
~> 10.0
 Project Readme

ProcUtils

A set of functional utilities for working with callables in Ruby.

Heavily inspired by lodash.

Introduction

I love Symbol#to_proc. It just feels good.

emails.each(&:deliver)

However, if your method takes an argument, you need to refactor to use a block.

emails.each { |email| email.deliver(:hello) }

What if you could do this?

emails.each(&:deliver.partial(:hello))

Installation

Add this line to your application's Gemfile:

gem 'proc_utils'

And then execute:

$ bundle

Or install it yourself as:

$ gem install proc_utils

Extending Procs

require 'proc_utils/core_ext/proc'

Now, procs will have the following methods:

  • partial
  • partial_right
  • bind
  • flip
  • wrap
  • compose
  • memoize
  • once

Extending Symbols

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:

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.