Giter Club home page Giter Club logo

for's Introduction

Overview

For is a Ruby library providing list comprehensions similar to those found in Clojure and many other languages. It is my celebration of the the fact that the August 2011 LinkedIn Hackday coincided with _whyday 2011.

Examples

For takes one or more sequence specifications and a block and returns an enumerable comprehension object. When the comprehension is enumerated, the block is executed once for each combination that can be formed by taking an element from each sequence:

For({ :x => (1..3) }, { :y => [:a, :b] }) do
  [x, y]
end.to_a
# => [[1, :a], [1, :b], [2, :a], [2, :b], [3, :a], [3, :b]]

Filter conditions may optionally be specified for the sequences:

For(
  { :x => (1..3), :where => Proc.new { x.odd? } },
  { :y => [:a, :b] }
) do
  [x, y]
end.to_a
# => [[1, :a], [1, :b], [3, :a], [3, :b]]

Conditions may also optionally be specified to the comprehension as a whole:

For(
  { :x => (1..4) },
  { :y => (1..4) },
  :where => Proc.new { x < y }
) do
  [x, y]
end.to_a
# => [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]

Supported Rubies

For has been tested with

  • Ruby 1.8.7
  • Ruby 1.9.2
  • JRuby 1.6.3

License

For is released under the MIT license. See License.txt for the details.

for's People

Contributors

gregspurrier avatar

Stargazers

Piotr Szotkowski avatar

Watchers

Piotr Szotkowski avatar James Cloos 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.