Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated.

learn more… | top users | synonyms (2)

0
votes
0answers
21 views

Finding triples between 1 and 10 that add to 7 [closed]

I have a list comprehension for finding triples between 1 and 10 that add to 7 but need to remove any duplicates (all but one of (1, 1, 5), (1, 5, 1), (5, 1, 1) should be removed). Can anyone point ...
5
votes
1answer
32 views

L system equations

This is my first program on my second try to learn haskell :) ...
1
vote
2answers
50 views
2
votes
1answer
42 views

Hackerrank, Service Lane in Haskell

Problem statement Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any ...
1
vote
3answers
75 views

Minimum element in a tuple

I'm solving exercise 2 from lecture 3 of Berkeley's CS 61A (2012): Write a function min_element that returns the minimum element in a tuple. ...
4
votes
2answers
94 views

Transforming an array in Ruby

I watched a presentation by Dave Thomas on Elixir where he gave an example problem that he solved using functional programming. He mentioned using Ruby to solve the same problem, but did not show an ...
7
votes
1answer
64 views

Small console app to execute some remote scripts

I'm learning F# and functional programming, from a background in C# and imperative/OOP. I've ported a small, one-off console app from C# to F#. The port worked (the app behaves the same way), but I'd ...
-1
votes
1answer
15 views

Matlab quadractic function with graph

I'm very new to MatLab and I am having some difficulty creating the code and just understanding what to put where. I got my quadratic formula to run and loop(Ex 4.2), but now I've been asked to have a ...
2
votes
2answers
96 views

Sequence processing problems

Problem 1: Sum the even numbers for the first n fibonacci numbers Solution: ...
2
votes
0answers
24 views

Functional, Loaner-Like Pattern For Consuming SQS Queues, Deleting Queue Items On Success

My program fetches input from a RabbitMQ or Amazaon SQS-like queue. There is not always input available in the queue. If a message is available, it triggers work. If that work is successful, ...
3
votes
1answer
44 views

Random Plinko path using functional programming style

In order to learn both scala and functional programming, I've been rewriting the projects from my introductory CS class in scala. One of the projects was a plinko game, where the user picks a slot to ...
5
votes
2answers
41 views

Checking in four directions for board game win

I have the following code which I would like to simplify in Haskell, although I'm not sure how. I recall that I can use monads to simplify a case chain when the result of the case leads onto a next ...
11
votes
2answers
104 views

Converting imperative style user input menu to functional programming style

I am currently trying to teach myself scala by rewriting projects from my intro CS class, which was taught in C++. In addition to just learning the syntax I am trying to gain understanding of how ...
11
votes
2answers
455 views

Printing removed items using lambdas and streams

I'm struggling to make my lambdas readable. I've seen various approaches. Below are three different examples that all do the same thing. Forgive the example: I suspect there are better actual ...
3
votes
2answers
69 views

“Invert” a JavaScript object hash whose values are arrays to produce a new object hash with keys as the elements of those original value vectors

Background lodash and underscore have an invert function that takes an object hash and converts it to a new one, which has keys as the input object's values and ...
0
votes
0answers
16 views

Multitenant Cassandra Query in Clojure

The following code handles querying for user data in a multitenant Cassandra database. Each tenant has their own keyspace and within that keyspace data about each tenants users is stored. This code ...
15
votes
1answer
71 views

Streaming Collatz

Challenge The recent question The 3n + 1 algorithm for a range inspired me to investigate a Java-8 dependent streaming mechanism for solving the programming challenge: For any two numbers ...
2
votes
1answer
34 views

Performance of parsing math functions

I wrote the following code as part of a larger application. This code takes a string that defines a mathematical function on such as r,y x[0], x[1] etc. or any ...
4
votes
1answer
122 views

Abstracting the process of finding the index of the maximum in Python

Suppose I want to find the index of the maximal value of a given sequence. In Matlab, this is: [value, index] = max(x) In Python, I would abstract the following ...
6
votes
2answers
52 views

2D lattice random walk plots in functional style

To practice writing code in the functional programming style, I wrote a program to plot two-dimensional lattice random walks. I'd appreciate any feedback about how to improve its "functionaliness". ...
0
votes
1answer
85 views

“Data Abstraction” and “Abstract Data Type” for a rational number [closed]

Below is implementation 1 of data abstraction for rational number using functional paradigm written in Python: ...
3
votes
3answers
131 views

Optimization of stack frame usage with recursion

For the given below exercise: Here is one method to check if a number is prime: ...
3
votes
2answers
65 views

Function returning higher order function

For the below given exercise: Define a function cycle which takes in three functions as arguments: f1, f2, f3. cycle will then return another function. The returned fuction should take in an ...
1
vote
1answer
52 views

File-to-fully qualified class name function

My instincts are telling me a seasoned Scala programmer will find my code less than optimal. As will no doubt be obvious, I'm a Java guy who has just started in with Scala. Is there a more ...
1
vote
1answer
77 views

Extracting tuples from Excel sheet

My code have too much nested option processing which makes it ugly. But it has an advantage it has no side effect and typesafe. ...
4
votes
3answers
68 views

Prime factorization of an integer

I have just started learning functional programming (Haskell) for fun after using imperative languages my whole life. I am looking for quick and simple tips from pros on how the particular code I just ...
10
votes
2answers
78 views

Test runner for Scala problems

I'm learning Scala and could use another set of eyes on the code below. I'm creating a test runner for the 99 scala problems set. I figure between actually solving the problems and working through the ...
2
votes
2answers
383 views

Failing fast by raising an exception with a custom message

This is a script that utilizes lazy exception throwing. What I do is decorate a function that might throw an exception to throw an exception with a formatted string. ...
1
vote
0answers
49 views

Using interface for generated functions or just create plain functions

I was wondering which code might be better. I'm abstracting away the rote code as follows: ...
4
votes
3answers
154 views

Functional programming approach to repeated function application

Control like if..else and while If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the ...
3
votes
2answers
74 views

Summation and product functions using functional paradigm

Below is the problem: Show that both summation and product are instances of a more general function, called accumulate, with the following signature: ...
3
votes
2answers
64 views

Functional-style linked list written in C

For my Operating Systems class, I needed a linked list data structure and didn't have one already written. During the course of thinking about how to implement a linked list again (it had been a ...
3
votes
1answer
121 views

Counting Lines and Sum of Lines

I have a small function that when passed a str that names a file that contains a program; it returns a 2-tuple with the number of the non-empty lines in that program, and the sum of the lengths of all ...
3
votes
1answer
49 views

UpdateGame function for Tetris

I am writing a Tetris game while learning Haskell and I'm trying to make the following code more concise and easier to read. How can I improve it? Note that the function is not finished yet (There is ...
0
votes
0answers
57 views

Natural sorting/comparing algorithm in TypeScript

This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
5
votes
4answers
240 views

Hailstone Sequences in Python

For the problem given: Douglas Hofstadter’s Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle. Pick a positive integer \$n\$ as the start. If \$n\$ ...
5
votes
1answer
59 views

Lightweight TicTacToe in F#

This is more of a 'model' of TicTacToe, as you'll see it's not "gameified" in the sense that it will allow for inputs and outputs nor will it record any "active" state of the game but those things are ...
6
votes
3answers
213 views

Print “n” number of “hello world”

I had come up with the following code: ...
10
votes
2answers
150 views

N-Queens functional

I'm trying to get a better grip on the new functional possibilities of Java 8. As an example, I took this very elegant Haskell snippet: ...
5
votes
2answers
292 views

Am I thinking functionally in these simple Haskell functions?

I'm learning Haskell using the University of Pennsylvania's online materials. I'm a few lessons in and was looking for some feedback about whether I'm thinking functionally enough or porting over my ...
5
votes
1answer
65 views

Popping from a list in state while a condition is true

I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling. To that end, I'm using ...
4
votes
1answer
90 views

Universal memoization decorator

I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with. So, if, say, we ...
1
vote
2answers
79 views
2
votes
2answers
69 views

List.containsSlice

In an effort to strengthen my functional programming, I'm reading Functional Programming in Scala. One of the assignments is to implement a function that does the same operation as ...
1
vote
2answers
110 views

Haskell monads: sum of primes

They say you cannot get out of the monad, but I need to use the result (at least for assertions / unit tests). But print how does it do it? Otherwise, I worked ...
4
votes
1answer
67 views

Reacting to Boolean state in reactive ViewModels

When this ViewModel loads we kick off the IsAuthenticatedCommand: If the result of ...
6
votes
3answers
241 views

Checking for balanced parentheses

I wrote a method to check if each parenthesis in a string is closed. It should take into account the order in which a parenthesis is presented, e.g. "hello)goodbye(" should return false even though ...
1
vote
0answers
71 views

Remove items, resize columns, shuffle a list

I'm at the very beginning of starting to learn object-oriented programming patterns in JavaScript and PHP. Up until now I've always coded in a purely functional pattern. I'm doing a lot of reading, ...
6
votes
1answer
116 views

Factory template method for generalized functors

(A quick note on terminology: I use 'generalized functor' to refer to a functor that can be initialized from any callable entity, similar to the definition from Alexandrescu's Modern C++ Design. I use ...
1
vote
0answers
111 views

Idiomatic Scala for nested map/flatmap

Does anybody have an idea on how to make this code more idiomatic? I tried to use scalaz Traverse, but it didn't really help. Given the types and method signatures: ...