The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [functional-programming]

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.

Filter by
Sorted by
Tagged with
0
votes
2answers
89 views

Adding polynomials represented as maps

I'm using maps to represent a polynomial. The key is the exponent and the value is the coefficient : Map(exp -> coef) e.g. ...
0
votes
2answers
337 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 <...
0
votes
2answers
45 views

Expand spreadsheet ranges to lists of cells in Scala

Problem Spreadsheet cells are referenced by column and row identifiers. Columns are labeled with alphabetical characters, starting with "A", "B", "C", ...; rows are numbered from 1 in ascending ...
0
votes
1answer
78 views

Functional List in C++ [closed]

This is rather toy example of immutable datatype in C++. I've tried to follow functional languages like Scheme, Racket - making list as a cons cell: list is list or is empty. ...
0
votes
1answer
274 views

JDBC wrapper in a functional manner

I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library. ...
0
votes
1answer
428 views

Count the number of digits in an integer using F# and log10

This code counts the number of digits in an integer. let digitCount number = (int) (log10 ((float)number)) + 1; For instance, it tells us ...
0
votes
1answer
85 views

Promisifying a third-party JS library with minimal code overhead

Context and Existing Code I am trying to "promisify" a third-party authentication library (auth0-js) written in JavaScript. Right now it uses callback functions and there are no plans to expose an <...
0
votes
1answer
70 views

Making a dynamic query based on a cookie change

I have a PHP function which sets/unsets something (category and tags) in the cookie and then makes a dynamic query based on it: ...
0
votes
1answer
919 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: ...
0
votes
1answer
43 views

Loading URLs via a case statement

I have the following code which loads in a URL based on the id of a user-clicked button. I'm looking to compress it down as much as possible, and make it more modular and reusable: ...
0
votes
1answer
67 views

JavaScript function for logging the members of an object (with horizontal alignment)

When iterating over the members of an object for logging the keys / values one gets a "stair case" effect. Therefore I wrote myself this function which takes care for a left-alignment of the values. ...
0
votes
1answer
34 views

ES6 block-scope variable usage

I am experimenting with ES6 using BabelJS in a codepen project you can find here. I am confused as to why my code breaks when I decide to use let instead of ...
0
votes
1answer
398 views

Functional Javascript Practice with AJAX

I am currently doing projects in freecodecamp.com to brush up on my javascript skills and just finished a weather report widget. It does the following: Gets api ...
0
votes
1answer
99 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 ...
0
votes
2answers
63 views

Including references in onResume Lifecycle

What's a more concise way to do this? It's way too verbose for my taste. ...
0
votes
0answers
29 views

Create a template literal tag to remove whitespace from a string

I'm just getting into functional programming (as in, just started reading the book) and as practice I'm trying to refactor a past answer I wrote to fit in line with the functional style. The ...
0
votes
0answers
69 views

Rewrite a Haskell function to be total

I've written this function to give the neighbours of a vertex in a graph: ...
0
votes
0answers
18 views

QTP/UFT Prints the time in takes to complete every task in a Log using VBScript

This script is meant to log the time it takes to complete functions in order to find the locations where performance could be improved in QTP. If a duplicate log is attempted, the script changes the ...
0
votes
2answers
66 views

Count Substrings for a binary string

Problem is taken from leet code. Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings ...
0
votes
0answers
53 views

Advent of Code 2017 Day 5 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 2nd part of Day 5): https://adventofcode.com/2017/...
0
votes
1answer
64 views

Is it possible to DRY these 2 methods of a tailrec Node Tree?

I have a Tree structure composed by Node class. I have to @tailrec method that are visiting up to the root. Those 2 methods ...
-1
votes
1answer
582 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: ...
-1
votes
1answer
45 views

Perform KS-test on Random Number Generator [closed]

I've just started practicing Functional Programming in Scala in some days. This is the code I used to perform KS-test on a random number generator. ...
-1
votes
1answer
73 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 ...
-1
votes
2answers
83 views

javascript reduce list of a multi attribute list of objects on one key but returning more than one attribute

Is there a better way to do this? I have a list of objects. I want the list has two values: an ID and a NAME. Both Name & ID are distinct taken separately of together. ...
-1
votes
1answer
67 views

Unbalanced Parenthesis correction

I'm prepping for a coding interview, and am examining the task of correcting unbalanced parentheses. The finger tree seems to be the right data structure. As a proof of concept I've used ...
-1
votes
2answers
194 views

Sanitize object's values in idiomatic JavaScript way [closed]

Oftentimes my JavaScript/TypeScript code becomes riddled with annoying code flow structures like below. Is there a way to do concise [functional] one-liners without being messy? Input: ...
-1
votes
1answer
907 views

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
-2
votes
1answer
52 views

7 pass file erasure [closed]

I am an aspiring C++ programmer and I have been programming for a few years off and on but I don't have much usable knowledge. Right now I am working on filesystem safety so I decided to write an ...
-2
votes
1answer
2k views

parking lot program in Java (BlueJ) [closed]

The program is as following - ...
-2
votes
1answer
39 views

A game that deals a high card to one of two players [closed]

So for my class, I have to design a game that will deal out one card to for each player. I also need to use functions to accomplish this one for the high card game, and another for the face value of ...
-2
votes
1answer
51 views

Functional vs non functional approach in python [closed]

This is not a task, but I want to know what the general consensus is on functional programming. Particularly functional programming in Python. The two snippets of code I am comparing are the ...
-2
votes
1answer
569 views

Decorator pattern using Java 8 [closed]

Wikipedia has an example of a decorator pattern here: https://en.wikipedia.org/wiki/Decorator_pattern#Second_example_.28coffee_making_scenario.29 I was trying to solve this using functional style ...
-2
votes
0answers
10 views

What is right way to define method typing in es6 arrow method [on hold]

while learning in react 16.8 with typescript code base, I came through many diffrent type definition pattern is been followed. so for the sake of consistency, which is the right way (recommendesld ...
-3
votes
4answers
775 views

Dependency injection using function references in C# [closed]

I understand that following the dependency injection principle, a class should ask for abstractions in the constructor and should not create them itself. This way they are not dependent on concrete ...