Giter VIP home page Giter VIP logo

proc_utils's Introduction

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.

proc_utils's People

Contributors

rzane avatar

Stargazers

Andy Maleh avatar Jason Garber avatar justin avatar Mike Nicholaides avatar Greg Sterndale avatar Patrick Smith avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.