Tagged Questions
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.
-1
votes
0answers
19 views
check my javascript code for logic, performance and robustness [on hold]
I wrote the below function in javascript that on button click from browser water the plant using solenoid connected to arduino.
In first attempt it tries to use local LAN URL if it timesout it ...
0
votes
0answers
25 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 ...
2
votes
0answers
32 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
40 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
36 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
80 views
+50
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. I've written two files so far, defining:
A public ...
3
votes
1answer
76 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
28 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
71 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
25 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
96 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
98 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 ...
-3
votes
0answers
33 views
Redesign to change class por functions
I would like to know if is possible to redesign the code above to make it functional:
lazyproperty.py
...
5
votes
4answers
198 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
62 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
38 views
3
votes
2answers
40 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:
...
3
votes
1answer
58 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
16 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
31 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
58 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
213 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
266 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
577 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
57 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
89 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
88 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
42 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
99 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
45 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
137 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
154 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 ...
2
votes
0answers
54 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
44 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
67 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
284 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
44 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
53 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
49 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
74 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 ...
1
vote
2answers
42 views
Functional method for storing a query string as a simple key-value object
I'm working on an isomorphic javascript module (query-hash) to handle query strings and base64 tokens. It's essentially a simple key-value object with methods for taking in data and giving it back in ...
2
votes
2answers
82 views
A trip down the single method interface rabbit hole
I responded to this question about designing around interdependant methods with the strategy pattern.
Afterwards I started thinking about the functional additions to java 8 and wondered if I was ...
7
votes
0answers
116 views
PLZ HELP MEH IMPROVA MEH LOLCAT CODEZ, WHUCH CALCULUTS FAWCTORIALS
SUNCE MEH BEEN WRUTEN CODEZ IN MUNY DIFFRNT PROGRAMMING LANGUAGES, MEH THOUGHTZ THAT ME TRY TO WRITE CODEZ IN AN ESOTERIC LANGUAGE. MEH CODEZ CALCULUTS A FAWCTORIAL OF UH USR INPUTTED NUMBAH IN ...
5
votes
1answer
51 views
“Guess My Number” with Racket
I am using the book "Realm of Racket" which was written by the people behind the Racket and Dr. Racket projects. It is a great book based on games, similar to the famous "Land of Lisp".
The first ...