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.
-3
votes
0answers
32 views
Sum array numbers instead of concatenate them [closed]
I want to use this JS code to add an array of numbers. It is not working , instead of doing addition it concatenates them: e.g.: 40+3 = 403 .
...
6
votes
2answers
76 views
Coin Change Kata in Immutable JS
I'm preparing for a job as a junior/intermediate JS developer. I'm comfortable with my ability to think in higher-order functions, but less confident in my syntax and style. (I have more experience in ...
1
vote
2answers
46 views
Proper use of tail recursion while forming a list
As a project to better develop my understanding of functional programming, I am writing a prime number generator in Scheme. I am using a simple brute-force algorithm to detect whether a number is ...
0
votes
1answer
56 views
Converting a 2D array to a JSON list
I am wondering if I could implement this in a cleaner, more elegant, strictly functional way:
...
-1
votes
0answers
19 views
F# tree-building function causes stack overflow in Xamarin Studio [migrated]
I'm trying to build up some rules in a tree structure, with logic gates i.e. and, not, or as well as conditions, e.g. property x equals value y. I wrote the most obvious recursive function first, ...
-2
votes
1answer
57 views
0
votes
0answers
29 views
PHP Function Style
I've written a small to medium size LAMP application and I'm in the process of refactoring the code.
I started with subsystems in separate files, and used includes to use them. I've move all those ...
4
votes
1answer
52 views
Compose n functions where the innermost function expects multiple arguments
I want to perform function composition like this:
f(g(...(z(x) (y));
I have already compn:
...
1
vote
0answers
43 views
Procedural TreeCreator
Some time ago asked a question about creating a tree from a flat collection.
I thought I try to rewrite it with C# 7. I could actually only use the new local functions in this example but there are ...
3
votes
0answers
42 views
Set manipulation (javascript arrays) using lodash
I'd like a more elegant and readable (if possible using functional programming style) for collection filtering (groupToAdd and groupToDelete collection handling)
Just getting rid of multiple _....
2
votes
0answers
93 views
Simple INI and command-line parsing, functional programming edition
I'm in the beginning stages of rewriting the model layer of my VBA Sync Tool in F#, to better learn functional programming. So far I've defined:
A public ...
3
votes
1answer
86 views
Functional API wrapper written in Scala
I've been working on an small API wrapper for the GitHub API using Scala (full source on GitHub). I'm still very new to the language, so I was hoping to get some feedback about a couple of design ...
1
vote
1answer
34 views
Parsing string into hash-map with 2D coordinates as keys
I had never programmed in a functional programming language before. I think that this function has large nesting. Is there way to rewrite it better? I am most worried about the use of "flatten". Is ...
12
votes
4answers
1k views
Create a function with an undetermined number of successive calls
As part of a programming challenge, we are tasked with creating a function with an undetermined number of successive calls. As an example, let's say the function returns simply the sum of the provided ...
7
votes
1answer
76 views
Generate iCalendar .ics files with events for astrological aspects
I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
1
vote
1answer
26 views
Nesting elements in a shallow hierarchy
I wrote some code to generate list items for a menu in Clojurescript. The intention is that the code takes parsed Markdown (Hiccup) that has been filtered down to h2...
4
votes
1answer
98 views
Pattern matching a ZMachine
Anyone following Eric Lippert's blog will know that he has an on going series where he is building a ZMachine in OCaml.
C# 7 is another step forward in adding features normally found in functional ...
4
votes
0answers
102 views
A* Algorithm in F#
Inspired by this post I looked up A* on wikipedia and went on with my own implementation as seen below where I try to mimic the pseudocode on Wikipedia but in a recursive manner. I would like any ...
5
votes
4answers
199 views
Remove contiguous elements in array in a more functional way
I try to remove elements in an array if the number of contiguous element is greater than two.
Here are the tests:
...
3
votes
1answer
55 views
Numerical streams example
I am reading "Java 8 In Action" (by Raoul-Gabriel Urma, Mario Fusco and Alan Mycroft), section 5.6.3, pages 116 and 117. The code that is presented handles calculating so-called "Pythagorean Triples". ...
2
votes
0answers
63 views
JVM wrapper for a Python function
Context:
The following function is used a JVM wrapper for a Python function, which is executed in a SQL-like environment. If you're interested in example usage you can check Cumulate arrays from ...
0
votes
1answer
41 views
How to better organize the declarations of these functions?
So as I understand it, you should always declare a function before it gets called.
However in the code below, how could this be restructured so that this philosophy is satisfied?
...
-1
votes
1answer
52 views
4
votes
2answers
46 views
Return the indices of the two numbers such that they add up to a specific target
(...as I learn Kotlin) I want to get the indices of the two numbers such that they add up to a specific target from a given array of integers.
Solution:
...
4
votes
1answer
66 views
Christmas Tree in Kotlin
Please review my code for printing a Christmas Tree.
The idea was to merge some functional programming ideas (immutability, streams) and OOP (every thing is a small object).
I'm looking for a review ...
0
votes
1answer
17 views
Use only necessary fields in an object for URL params
I'm trying to cleanly grab some fields I need from an object.
The scenario is this:
I've got an object that is stored with certain 'extra' properties that exist because of the way we've set up our ...
0
votes
0answers
32 views
Python tic-tac-toe game IMPROVED PROCEDURAL PROGRAMMING ONLY
I made a tic-tac-toe game, a player versus player version (plan on doing an AI later...)
Note: I have tried not to utilize objects because I haven't really gotten there yet. A previous version (see ...
3
votes
1answer
61 views
Transformations an array, combination of between map and reduce
I'm working on a function that reduces pairs of elements if they meet some criteria.
For example, given an array: ["1", "2", "a", "b", "3", "4"] I want to ...
7
votes
2answers
216 views
Navigating a bounded 2D list (Advent of Code, Day 2: “Bathroom Security”)
I'm trying to solve the following Advent of Code problem in F# for practice.
Description of problem (can be found here):
Basically, there's a 'key pad' that I need to figure the combination to. To ...
12
votes
1answer
267 views
American Checkers
I am implementing the logic for a Checkers game in F#. I am writing my code in a library so it can be called from any UI provider, and am trying to do it in good FP style. I currently have the ...
12
votes
1answer
586 views
Creating a pipeline operator in Java
I wrote the following as more of an experiment than anything else, but I thought it would be fun to share and maybe get some feedback!
Motivation: I started looking at some functional languages and ...
3
votes
0answers
60 views
Voting app in JavaScript using Ramda
I'm just learning functional programming in JavaScript using Ramda.
I took this tutorial and implemented the server core.js component using Ramda.
The idea is that we'll have a collection of ...
1
vote
1answer
96 views
Cons List in Python
It make sense to not allow links to external code hosting, so I restated my question. This is classical cons list in python using Abstract Base Class interface. Constructor is in fact out of the Cons ...
3
votes
0answers
42 views
Computing nth roots of a number - SICP exercise 1.45
From SICP
Exercise 1.45:
We saw in 1.3.3 that attempting to compute square roots
by naively finding a fixed point of x/y does not converge, and that
this can be fixed by average damping.
...
7
votes
2answers
89 views
Probabilistic Matrix Inspection - Suggested by a paper, implemented by me
I have read this paper and I actually found it interesting.
This is an attempt to implement the proposed algorithm. I would like to know:
Is my algorithm correct by what is discribed in the paper?
...
1
vote
2answers
43 views
Validating Input concerns
I would like to find out if there's a cleaner way to go about validating input before it goes into a function. What I'm doing seems like a lot of code, I'm sure there's a better way. I would also ...
1
vote
1answer
56 views
7
votes
2answers
105 views
Recursive higher-order function
I have implemented a through function for myself in a project.
Since I am still quite new in python and want to learn it correctly, I would be happy about any ...
0
votes
2answers
49 views
Highest number in a list with Racket
I am trying to build a function to find the highest number in a list without using the built-in functions of "apply" and "max".
I created the following code:
...
5
votes
2answers
141 views
Calculating the count of integer partitions of a number (uses stateful vectors internally)
I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem:
$$P(n) = ...
3
votes
0answers
183 views
D3.js multi-line graph
Here is my JS code which uses the D3.js library (mostly snipped from other examples). I want to graph the acceleration of a point in 3D-space which changes with respect to time. The X-axis of the ...
3
votes
1answer
63 views
Algebraic Effect Monad to separate pure and impure code
I want to write my C# code in a way which makes effects (state, I/O, etc) explicit in the type signature. I have started to understand monads, and have some acquaintance with algebraic effects, though ...
3
votes
0answers
45 views
OAuth 1.0 signature using Ramda
I created an OAuth 1.0 signature generator using Ramda based on this.
I'm just getting to grips with it, so was wondering if someone more familiar with Ramda and functional programming would give me ...
3
votes
1answer
69 views
JavaScript Functional Programming Bank Account, Shop and Customer
Motivation
I have worked extensively with JavaScript and have grown fond of some of its functional aspects. This got me wondering how one could implement the canonical example of a bank account - and ...
12
votes
1answer
285 views
Cat fight (with rockets)
My code is attempting to implement FP in an efficient / readable manner into some of my video games. I realize this may be a bit subjective, but I feel there is enough merit / objectivity to be of ...
2
votes
1answer
47 views
Comparing corresponding elements of two equal-length arrays
I have a helper function I wrote, but it feels like something _.lodash already does or could do if I knew the library better.
...
3
votes
1answer
55 views
Naive JS implementation of tidyr's gather function
Tidyr is an R package for creating tidy data.
(tl;dr)
In short, it provides an interface (gather) for restructuring a table into a "tidy" format. For our purposes ...
3
votes
0answers
52 views
Calculating a snowballing investment
I'm currently taking a JavaScript class. I was fairly familiar with JavaScript and coding in general, so I decided to teach myself functional programming on the side. It's been great, my teacher's ...
5
votes
1answer
39 views
Python-like enumerate and join
I'm new to Rust and trying to convert some Python to Rust. I have the following in Python:
...
1
vote
2answers
89 views
Reverse the order of a list in Racket
I am using the SICP book. There is an exercise in which you need to create a function that will receive a list as an argument and return a list with the same elements in a reverse order.
I know there ...