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)

1
vote
0answers
17 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: ...
2
votes
0answers
12 views

Using my own Optional type with fold method in groovy

I have written an Optional type in groovy roughly based on java8s Optional. I implemented and use a fold method and would like to know if it can be improved. First, ...
3
votes
1answer
41 views

Generating a game board with squares in a rectangle

I am trying to generate a game board (similar to a Monopoly board). I am new to Scala and am thinking that there may be a better way to do this. But improvements to the code are also welcome. ...
3
votes
0answers
47 views

Making PHP composable and look functional

I've found myself on numerous occasions needing to with large text-files, where joining this on that, and filtering this out on arbitrary conditions. The first couple of times, this turned into a ...
3
votes
5answers
206 views

Evaluating Valid Date

I want to write a function which returns true if a selected date is smaller than the current date, else return false. This function is working as expected but I want to know the best possible way to ...
3
votes
2answers
56 views

zipWith function in Scala

My implementation works, but it looks very ugly. Curious to see how it's better implemented. The zipWith function takes a list of lists (...
2
votes
3answers
66 views

Removing nested blocks from a string

I wrote this function in scala that uses tail recursion to remove nested blocks from a text. Usage examples: ...
5
votes
1answer
74 views

Converting an object to an array of objects

I've written a method that takes an object whose keys are arrays and converts it to an array of objects. I feel like the code is fairly complex, after waiting a week or so and revisiting it, I don't ...
0
votes
2answers
45 views

Including references in onResume Lifecycle

What's a more concise way to do this? It's way too verbose for my taste. ...
4
votes
1answer
51 views

Function to get NGrams fast in Haskell

Is this a good way to get all sublists of a sequence/list that have a given length? An inefficient way to do it would be something like ...
2
votes
2answers
64 views

jsperf for js objects vs array tuples

I'm getting more and more into programming js in a functional manner which makes heavy use of multiple returns via tuples (especially useful with recursion). Also, a pattern that I use often is ...
10
votes
2answers
124 views

“Pure” functional simple Scala battle game simulation

I am a long time imperative programmer (mostly C++) taking my first forays into functional programming with Scala. I am following some online tutorials about functional programming and Scala and I'm ...
0
votes
1answer
86 views

Approximate integral in one line of code

This is what I came up with: Version 1: ...
0
votes
1answer
56 views

Project Euler 3 in F#

I'm looking for some general feedback on my solution to Project Euler challenge 3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
2
votes
2answers
64 views

Project Euler #2 in F#

Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million. My first attempt at this problem using functional programming with F#. I would've liked to use some kind of ...
7
votes
2answers
127 views

Defining a simple function-calling operator

I have been writing Swift code for a while and have read a lot of tutorials about how functional paradigms can be applied to Swift. I defined a simple operator: ...
10
votes
2answers
161 views

Is this Bridges code F# idiomatic?

Introduction I'm primarily a C# programmer, just starting out with learning F#. I found myself with a problem which felt like it was appropriate for a functional language, and now that I have the ...
0
votes
0answers
57 views

Functional Typescript/Javascript

The past month I've been trying to learn Javascript through Typescript and my adventures have led me through the subjects of asynchronous and functional programming along the way. In order to try and ...
0
votes
2answers
72 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 ...
9
votes
1answer
87 views

Function composition using std::bind

Given a number of functions f1, f2, f3, ..., fn I ...
4
votes
1answer
90 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
98 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
165 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
88 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
203 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
57 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
44 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
97 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
48 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
67 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
77 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
222 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
47 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
63 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
5
votes
1answer
102 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
52 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
264 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
163 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
324 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
280 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
90 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
60 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: ...
3
votes
1answer
64 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
142 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
171 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
156 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
114 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
89 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, ...