Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7987633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:12:16+00:00 2026-06-04T12:12:16+00:00

The short code in title is in Haskell, it does things like list.map {|x|

  • 0

The short code in title is in Haskell, it does things like

list.map {|x| x + 1}

in ruby.

While I know that manner, but what I want to know is, is there any more elegant manners to implement same thing in ruby like in Haskell.

I really love the to_proc shortcut in ruby, like this form:

[1,2,3,4].map(&:to_s)
[1,2,3,4].inject(&:+)

But this only accept exactly matching argument number between the Proc’s and method.

I’m trying to seek a way that allow passing one or more arguments extra into the Proc, and without using an useless temporary block/variable like what the first demonstration does.

I want to do like this:

[1,2,3,4].map(&:+(1))

Does ruby have similar manners to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:12:17+00:00Added an answer on June 4, 2026 at 12:12 pm

    Use the ampex gem, which lets you use methods of X to build up any proc one one variable. Here’s an example from its spec:

    ["a", "b", "c"].map(&X * 2).should == ["aa", "bb", "cc"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this code to sort an unordered list with regards to their title
In short: For this code: Encoding.ASCII.GetBytes(‚) I want the output to be 130, but
I wrote this short test code, but it didn't work. What am I doing
As the title states, I would like to short circuit the onchange (inside of
Like in title, I would like to fetch a list of all available projects
I get the error in the title in the following code: std::vector<short> GetIndicesFromID3DXMesh(ID3DXMesh* model)
The title description basically says it all. I'd like to use something that requires
I have in a sidebar: <div id=yyy> [shortcode]</div> It outputs a title that when
Any short code to get the database table prefix in cakephp controller action ?
in this short code: class X { private: class Y { public: typedef void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.