All Questions
Tagged with functional-programming ruby
130 questions
2 votes
4 answers
198 views
How to pre-fill arguments to a function in Ruby?
Let's say I have a function foo: def foo(A, B, C) A + B + C end And I call it like this, with only the last parameter changing: foo("foo", "bar", "123") foo("foo&...
-1 votes
1 answer
158 views
How do you do reading from a file and then split that file into multiple files with Clojure? [closed]
I have a text file, that need to be split in the following way: first line is an identifier and must be at the top of every file created, following lines are a pair of digits separated by a comma: ...
1 vote
2 answers
125 views
How to avoid a hierarchy in ruby classes?
I am processing 2-dimensional shapes in ruby. I have a Point class with x and y attribute, and a Line class which has two end points. Later in the process chain, I often want to identify and process ...
1 vote
1 answer
70 views
How do these 'reverse' and 'twist' functions work in Ruby? (functional programming)
I redefined function fold using reduce method in Ruby. def fold(f, init, lst) lst.reduce(init){|w, a| f.call(w, a)} end I have reverse and twist functions below and examples on how they should ...
1 vote
3 answers
451 views
Creating a Ruby Hash Map in a Functional Way
I have an array I want to turn into a hash map keyed by the item and with an array of indices as the value. For example arr = ["a", "b", "c", "a"] would ...
1 vote
4 answers
81 views
How to sum arrays based on the first field
I have 3 array of hashes: a = [{name: 'Identifier', value: 500}, {name: 'Identifier2', value: 50 }] b = [{name: 'Identifier', value: 500}, {name: 'Identifier2', value: 50 }] c = [{name: 'Identifier', ...
0 votes
1 answer
36 views
Selecting data from structured data, but the elegant functional way
Apparently, my ability to think functional withered over time. I have problems to select a sub-dataset from a dataset. I can solve the problem the hacky imperative style, but I believe, there is a ...
-1 votes
2 answers
49 views
Return characters between each set of delimiters in a string
I have a string that looks like this: "[hello][my][friend]" I'm interested in returning an array like ["hello", "my", "friend"] How can I do this in Ruby?