Giter Club home page Giter Club logo

pipe_envy's Introduction

Lines of Code Code Status Dependency Status Build Status Coverage Status Downloads

Sponsor

PipeEnvy

WARNING

This lib is experimental & is probably not a good idea.

PipeEnvy overrides the pipe operator | on Array & Integer. It also adds it to Object.

Fun Stuff

Elixir's pipe operator is very cool & supports intuitive reasoning about data transformations similar to Unix pipelines.

"Elixir Rocks" |> String.upcase |> String.split # => ["ELIXIR", "ROCKS"]

Rubyists can now enjoy this same mental model of data transformation.

gem install pipe_envy
require "pipe_envy"

# refinements that apply extensions to Object, Array, & Integer in the current scope
using PipeEnvy

"Ruby Rocks" | :upcase | :split # => ["RUBY", "ROCKS"]

Here's a more sophisticated albeit contrived example. Notice that methods which require arguments are piped as Arrays.

magic = (1..100) \
  | :to_a \
  | [:select!, -> (i) { i.even? }] \
  | [:map, -> (i) { i ** 10 }] \
  | :sum \
  | Math.method(:sqrt) \
  | :to_s \
  | :chars \
  | :reverse \
  | [:[], 3] \
  | :to_i

# => 7

Be sure to check out Chainable Methods which offers similar behavior.

Here's another example similar to the one on the chainable_methods repo.

magic = "foo bar http://github.com/hopsoft/pipe_envy foo bar" \
  | URI.method(:extract) \
  | :first \
  | URI.method(:parse) \
  | :open \
  | :readlines \
  | :join \
  | Nokogiri::HTML.method(:parse) \
  | [:css, "h1"] \
  | :first \
  | :text \
  | :strip

# => "hopsoft/pipe_envy"

pipe_envy's People

Contributors

hopsoft 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.