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)

-5
votes
0answers
23 views

Ten Green Bottles please give me a hand i cant work it out [on hold]

This open a file given as filename for reading returns the String containing the contents of the file ...
5
votes
1answer
64 views

Curry function with function constructor

Shall I make a curry function this way, or is it best to avoid Function constructor in all means? What I want to know is if this is "bad practice" and how else currying can be done. For instance, one ...
2
votes
0answers
30 views

Python tokenizer in Haskell + Parsec

I wrote a tokenizer/lexer (difference?) for Python in Haskell: this is my code on GitHub. I already tested it out with some of CPython's standard library scripts, and it doesn't fail. However, it ...
4
votes
1answer
52 views

HackerRank - Candies

Here is the solution I've written for Hacker Rank Candies challenge. It uses dynamic programming (memoization in a boxed array). I'm interested on what could be done to improve this code in term of ...
3
votes
1answer
105 views

Prime number verifier

I solved this prime number verifier problem: ...
6
votes
1answer
68 views

Hello Functional World: Counting occurrences of each letter

Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps. I set myself a simple challenge to count the instances of each ...
5
votes
2answers
298 views

Mock/Stub out filesystem in F# for unit testing

I'm looking to do some basic verification testing on my functions that write to the filesystem. I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
6
votes
3answers
88 views

Number of Chocolates to Gluttonize in Clojure

I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters: ...
3
votes
3answers
113 views

Creating an array of objects for dictionaries

I wrote a piece of code that creates an array of objects based on the array of dictionaries. The problem is that my solution uses multiple loops imperatively. Let's consider the following case. There ...
6
votes
1answer
61 views

Equilibrium Index Implementation

I have come up with a solution to the equilibrium index problem with help from the answers off here: ...
1
vote
1answer
72 views

For Loop with Index to Functional

Trying to simply my code below: ...
5
votes
2answers
96 views

Reading input from console in F# (as a sequence of lines)

Consuming input line-by-line until the end is often useful. In C# I would write the following loop while ((line = Console.ReadLine()) != null) {. I wanted to do ...
1
vote
0answers
27 views

Monoalphatic and Polialphabetic cipher in Ruby

This code encrypts a text with mono-alphabetic and poli-alphabetic substitutions ciphers. For further info see: Mono-alphabetic/Caesar Cipher Poli-alphabetic cipher ...
7
votes
1answer
57 views

Using delegates to avoid duplicate creation of resources

I'm writing a PCL that uses an HttpClient to go visit a few sites and extract data from them. My initial code looked like this: ...
-1
votes
1answer
64 views

Filtering/mapping strategies

This is real JavaScript/Lodash code used in a project I'm currently working on, but actually this particular question bothers me quite often regardless of the language. Say, I need to generate some ...
2
votes
0answers
35 views

Passing around and using Python dicts [closed]

I have an Excel file - a profit spreadsheet - which has one tab per product range. The tabs are defined and named, but apart from that, the file contains no data (yet). I wish to use ...
8
votes
1answer
168 views

Functional Programming Library

I have started putting together a functional programming library in C# which is somewhat inspired by scalaz and the book Functional Programming in Scala. I am hoping to get some feedback on the Monad ...
3
votes
1answer
89 views

Building and flattening a dependency graph

The Problem Given a list of dependencies ('a * 'a) list where the first item has a dependency on the second item, construct a dependency graph and then 'flatten' ...
1
vote
1answer
32 views

Extracting a list of hyperlinks [closed]

I need to produce a list objCollector with some results: ...
4
votes
1answer
120 views

Sudoku game logic

I am trying to create a Sudoku game in F# and I'm having a bit of trouble with the file reading and writing. But since I've also just started programming in f# I would like to check if my thinking is ...
7
votes
1answer
208 views

Functional programming in Python: 2048 merge functions

I've written the core functions for a basic 2048 game. I know Python isn't a functional programming language, but I like the "functional style" (easier to maintain, simple to understand, more ...
3
votes
0answers
40 views

Factory for arbitrarily high-order operations

Grade 0: ++ This is so low that it is boring; the operation of grade 0 is incrementing or counting up, for example: ...
4
votes
0answers
49 views

Selecting subset of size k using recursion

Sometimes I need to implement recursive algorithms that pass a certain state from one recursive call to another. For example, a greedy subset selection: we have a set of candidate objects, and we ...
10
votes
1answer
120 views

Detecting cycles in a directed graph without using mutable sets of nodes

I recently came across the classic algorithm for detecting cycles in a directed graph using recursive DFS. This implementation makes use of a stack to track nodes currently being visited and an extra ...
3
votes
1answer
84 views

Currying in Matlab

As MATLAB has a hard maximum of 10 input arguments it's possible, but ugly, to implement a curry function in this manner: ...
10
votes
1answer
97 views

Hunt the wumpus: Functional JavaScript (Node) with Lodash

I'd like a code review of the following simple implementation of the classic game Hunt the Wumpus I'm trying to use JavaScript in the most "functional" way. To help me, I'm using lodash and ES6. ...
6
votes
0answers
77 views

Higher-order Prolog predicates combine/3 and reduce/3

I'm trying to find useful versatile meta-predicates that are different from the vanilla ones offered currently by library(apply). How about the following two: ...
2
votes
3answers
49 views

Tail-Recursion to get a Map of word counts

I want to read a file and store the number of occurrences of each word in a Map, using tail recursion. I came up with the following; it seems to work; does it look like it's right? ...
4
votes
1answer
61 views

Continuable if error is null

I made a method that I can use to avoid having to handle errors from callbacks. What it does is, call the passed method only if the first argument is null. So essentially it will bypass to the last ...
5
votes
1answer
38 views

L system equations

This is my first program on my second try to learn haskell :) ...
1
vote
2answers
70 views
3
votes
1answer
84 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
87 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
110 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
111 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 ...
3
votes
2answers
125 views

Sequence processing problems

Problem 1: Sum the even numbers for the first n fibonacci numbers Solution: ...
2
votes
0answers
28 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
57 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
54 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
146 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
482 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
192 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
1answer
50 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 ...
16
votes
1answer
90 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
52 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
184 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
77 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
114 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
151 views

Optimization of stack frame usage with recursion

For the given below exercise: Here is one method to check if a number is prime: ...