Functional programming in Ruby (Was: Reducing Enumerable (and writing again))

Have you used anything like
GitHub - github/github-ds: A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection for error handling? I'm wondering if that's a useful next step (after introducing some immutability and attempting to isolate side effects) that could be a gateway to other functional techniques. I've used it in a codebase and I
*think* it was an improvement.

No, I've not tried it. I see the appeal from a functional perspective, but a part of me is not really buying it. Nothing is stopping you from chaining methods in Ruby without it, apart from the fact that a method could raise an exception, and if a method raises an exception then presumably that's for a good reason?

Instead of:

    Result.new(foo).then Result.new(bar)

Why not just:

    begin; bar( foo )
    rescue; .....
    end

It seems like what Result is mostly bringing to the table is Syntactic sugar, and I _like_ Ruby syntax, so...

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer&gt;

I hear you. I'm not entirely sold on it yet either... but I feel like it wraps things up a bit more nicely. I'm not sure I can articulate why though.

One thing I saw on the internet somewhere that was helpful for me - someone said "if you're programming in a functional style your methods will look more like expressions". So instead of:

def foo
x = get_something
x.twiddle!
x
end

you might do:

def foo
get_something.tap {|x| x.twiddle! }
end

For some reason that kind of struck a chord with me.

···

On 11/2/17 9:54 AM, Andy Jones wrote:

No, I've not tried it. I see the appeal from a functional perspective, but a part of me is not really buying it. Nothing is stopping you from chaining methods in Ruby without it, apart from the fact that a method could raise an exception, and if a method raises an exception then presumably that's for a good reason?
Instead of:

     Result.new(foo).then Result.new(bar)

Why not just:

     begin; bar( foo )
     rescue; .....
     end

It seems like what Result is mostly bringing to the table is Syntactic sugar, and I _like_ Ruby syntax, so...

Thank you.

Get Outlook for Android<Bing;

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Tom Copeland <tom@thomasleecopeland.com>
Sent: Thursday, November 2, 2017 8:09:10 PM
To: Ruby users
Subject: Re: Functional programming in Ruby (Was: Reducing Enumerable (and writing again))

On 11/2/17 9:54 AM, Andy Jones wrote:

No, I've not tried it. I see the appeal from a functional perspective,
but a part of me is not really buying it. Nothing is stopping you from
chaining methods in Ruby without it, apart from the fact that a method
could raise an exception, and if a method raises an exception then
presumably that's for a good reason?
Instead of:

     Result.new(foo).then Result.new(bar)

Why not just:

     begin; bar( foo )
     rescue; .....
     end

It seems like what Result is mostly bringing to the table is Syntactic sugar, and I _like_ Ruby syntax, so...

I hear you. I'm not entirely sold on it yet either... but I feel like
it wraps things up a bit more nicely. I'm not sure I can articulate why
though.

One thing I saw on the internet somewhere that was helpful for me -
someone said "if you're programming in a functional style your methods
will look more like expressions". So instead of:

def foo
   x = get_something
   x.twiddle!
   x
end

you might do:

def foo
   get_something.tap {|x| x.twiddle! }
end

For some reason that kind of struck a chord with me.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.ruby-lang.org%2Fcgi-bin%2Fmailman%2Foptions%2Fruby-talk&data=02|01|ac.kamal%40hotmail.com|9c3fe7cc2bb042b2ac5508d521fb5092|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|636452285620582841&sdata=3B%2Ftn8EGHWeT6DAlOBju4%2FObiuX9FCcrm5gjhrg9tOs%3D&reserved=0&gt;