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 (1)

0
votes
0answers
7 views

Pick a column for each row by column-header name

I am parsing a table: |-------| |Bar|Foo| |-------| | 5 | 6 | |'f'|'g'| | 1 | 8 | |_______| I've tried a number of ways of writing a ...
8
votes
0answers
46 views

Function composition using std::bind

Given a number of functions f1, f2, f3, ..., fn I ...
4
votes
1answer
71 views

Polyalphabetic cipher

I am trying to write the simplest to undestand code possible, each function has documentation and examples and I tried to use the best style possible. ...
-1
votes
1answer
50 views

ArrayList implementation in C [closed]

Although I know I can use calloc then realloc to make a dynamic array in C, and that I also need a variable to keep track of the ...
8
votes
3answers
143 views

Compare values of elements in Stream

I'm having fun with Java's Stream library and lambdas. The following code looks for persons within a list that have the same ID (which might indicate that something's wrong with the data) and prints ...
6
votes
2answers
85 views

Getting functional Common Lisp code for handling state in a SDL animation

The following code draws a red rectangle bouncing between the borders of a white display. I'm not particularly happy with the update function: ...
4
votes
2answers
183 views

Detecting properly nested parenthesis using functional programming

So I have this code that is my attempt at a coding test from Codility. While my code produces correct results according to the requirements, (which unfortunately are copyrighted so I don't think I can ...
4
votes
2answers
43 views

First multi-line Haskell program, extensive use of Maybe type

I'm reading through Write Yourself a Scheme after finishing going through Learn You a Haskell. I attempted one of the early exercises: writing a program to get an operator and two numbers and do a ...
2
votes
0answers
39 views

Super Resolution in Wolfram Language

An approach to Super Resolution in the Wolfram Language/Mathematica. In effect, large parts of the image that are similar to small parts are shrunk and used to replace them, in doing so ...
4
votes
2answers
70 views

Higher Order Functions in VBA, the dirty way

I have been building a small library of VBA functions. I have a small section with higher order functions that I'd like to share. It uses strings as delegates/function pointers and ...
1
vote
0answers
24 views

Infix epression evaluation

I'm looking for some feedback on my OCaml implementation of some methods to translate infix expressions to postfix and then evaluate them. I'm very new to OCaml, coming from C#/Java and JavaScript ...
4
votes
1answer
56 views
4
votes
0answers
62 views

Refactoring while-do array comparison function into tail recursion with F#

As part 2 of my other question concerning this long running project I've been inquiring about on CR, I reimplemented my generic function for determining if an array of arrays is a sub-array or ...
2
votes
1answer
63 views

Refactoring while-do into tail recursion with F#

I have a while-do loop nested inside a while-do loop in my program, due to it needing to iterate in two dimensions through an array of arrays, and originally my loop looked like this: ...
7
votes
3answers
206 views

Functional Programming style in F#

I'm normally a C# developer, but I've started to learn F# and I want to make sure I'm writing code in a functional way that suits the language. I've quickly pieced this together with my knowledge from ...
3
votes
1answer
42 views

Erlang pattern matching excersise

I recently started my first project with Erlang. I've been skimming documentation and various books to get the information I need, and it's going well, but now that I have something that works I want ...
4
votes
0answers
61 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
5
votes
1answer
89 views

Algorithm to Iterate All Possible Strings in Clojure

I'm fairly new to Clojure and I struggled a bit coming up with a nice Clojure-y solution for implementing an algorithm for one of my applications. The real issue I'm trying to solve would require a ...
2
votes
0answers
45 views

A solution to the AST Typing Problem

Expression trees are the bread and butter of functional programming but when it comes to adding additional information to an established tree it can be difficult to incorporate such changes without ...
3
votes
1answer
150 views

Determining maximum profit to be made from selling shares

Question Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next \$N\$ days. ...
6
votes
2answers
111 views

Printing inputted, largest, odd integer

The program asks the user to input 10 integers, and then prints the largest odd number that was entered. If no odd number was entered, it prints a message to that effect. ...
3
votes
2answers
100 views

Timing Project Euler Problem 1

Is there a better way to time the functions and print the result and function name dynamically? ...
13
votes
1answer
314 views

Yet another FizzBuzz

Since today is apparently a good day for...unlikely FizzBuzz implementations, I decided to contribute another, this one in C++: ...
3
votes
1answer
160 views

Binary search in functional-style Scala

Curious to know how I can improve it, especially the pattern matching part seems a bit repetitive at the moment (lots of case x if ds(x)) ...
2
votes
1answer
62 views

Folding with trees

I was trying to implement a foldTree function to generate a balanced binary tree from a list of values using foldr (Question 2 ...
2
votes
1answer
56 views

Initializing an array of relative coordinates of all adjacent 2D matrix cells

The program should output this: _1 _1 _1 0 _1 1 0 _1 0 1 1 _1 1 0 1 1 Currently I have this code: ...
2
votes
1answer
49 views

Python Vector implementation that acts as a class and also a collection of staticmethods

Recently I've been wondering about ways of implementing objects in code that can be represented by other primitives. An example of this is a Vector, which can be represented by a Vector\$N\$D where ...
3
votes
2answers
123 views

Is there a better way to write these two nested loops in Erlang?

Since one month, I'm learning Erlang and I like it so much. Today, I wrote an algorithm to solve a problem. Some time ago, I used two nested for loops in C# to ...
3
votes
1answer
110 views

Scala Tic Tac Toe Game

This is my first Scala game. I would love some feedback on my coding style, or your brief input on how you would do it. ...
4
votes
2answers
118 views

Making backtracking Sudoku solver more functional

I'm implementing the backtracking solving algorithm for a Sudoku in F#. I'm wondering if I could make my code better respect the functional programming paradigm or even just making it simpler/better. ...
1
vote
1answer
107 views

Finding an entry in a Hashmap

I've been playing around with functional programming for a while now and just started learning Clojure. So the problem I'm trying to solve is the following: I have a tree-like hashmap of tasks where ...
5
votes
2answers
85 views

Beginner Project: Bunny City

I am a Java programmer, and I just recently started learning Scala for fun. I found a group of projects here, and I tried to do the graduation excercise. The problem is, my code looks a lot like java, ...
4
votes
1answer
83 views

Resize renderer on browser window size change

For a game, there is some WebGLRenderer object that wraps around canvas element. There is need to update it's size when browser window size changes. Here goes my current code written using BaconJS. ...
1
vote
1answer
103 views

Converting object oriented style code to functional in Scala

I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level ...
4
votes
1answer
78 views

Neatly Transforming Anorm ResultSet Into Map[Parent , (Set[Child1], Set[Child2]))]

I have a table Bill containing Bills with 0...n relationships to Material and ...
3
votes
2answers
79 views

Clojure function composition: logging results of an action performed by a “pure” function

I'm wondering how I could compose this program better allow it to grow more functionality without constant refactoring. This is my code sample for Hacker School, so I'm less married to the results ...
2
votes
1answer
120 views

Removing duplicates from list and filtering non-letter characters

I'm just starting out in Haskell and have been set an assignment for uni where I have to create a reverse index of words in a text file and find what line numbers they appear on. I also have to remove ...
4
votes
1answer
46 views

Counting items in categories

I'm an experienced programmer that also has a little experience with functional programming, although mostly theoretical (as in hobby-level reading and very minor projects). I recently decided to ...
3
votes
3answers
76 views

Curious fractions in functional Ruby

Problem 33 in Project Euler asks: The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is ...
6
votes
2answers
50 views

Refactor module for calls to internal image service

Looking for help refactoring the following code to follow a Functional Programming paradigm. The first function builds a configuration object with default settings and optional presets, while the ...
2
votes
1answer
60 views

Which one of these both run-length decoding algorithm is the most optimal?

I'm working on Ocaml.org 99 problems, and I solved the run-length decode one. Here is the solution given by the site: ...
2
votes
1answer
41 views

Aggregation of a collection of object's nested array-properties

Use Case So our lead programmer loves to follow the NIH Anti-Pattern and consequently I'm not allowed to use Underscore.js and can only use Vanilla JS... and we have to support IE8. The goal is to ...
6
votes
1answer
331 views

BBCode to HTML converter using functional programming

I was inspired to write a BBCode to HTML converter as I'm currently learning functional programming. I wanted achieve functional cohesion. jsFiddle I'd like feedback on: structuring of the code. ...
5
votes
2answers
97 views

Decomposing bitfield with Haskell: is recursion the only way to do this?

Here's a program to take a bitfield like 7 and decompose it into the flags [1,2,4]. Ignore that the algorithm for doing this doesn't use bit shifting/is stupid. Problems: it seems like I have to have ...
6
votes
2answers
129 views

Package manager in Clojure

I wrote a package manager in clojure that does 5 things: depend a b //creates a and b (if they don't exist) and adds dependency on a install a //installs a and its dependencies list //prints out ...
14
votes
3answers
1k views

Effective use of multiple streams

I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code. This code finds the Cartesian product of ...
11
votes
1answer
168 views

Refractoring OOP vs. Functional Programming Approach

I am writing a python script that will call mandrills export activity api for every blog on a worpress mu install except for the main site. The script is designed to be called from a cron job on a ...
6
votes
1answer
164 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...