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
3
votes
1answer
68 views

Setting new values in array based on query results

I have some code which uses nested foreach loops to take the results of a query and drill down into the data, reassigning into a main data array at each level of the foreach nesting. The problem is ...
3
votes
3answers
821 views

Readability of array_* vs foreach in PHP for filtering and extracting

With functional programming all the rage, I feel I should be using PHP's array_* functions more. But when I compare these two identical implementations, I can't ...
3
votes
1answer
227 views

Using Ramda in point-free way to transform data into new format

Recently I asked on SO about using point free methods to rearrange some data The idea was to turn data in this format: ...
1
vote
0answers
322 views

Fetching weather data from API

I was experimenting with some code to fetch the current weather data as well as getting the hourly forecast. I could have done ...
0
votes
2answers
63 views

Updating persons in database with newly created addresses [closed]

I have the following code, and I'd like to refactor it to a more functional way: ...
7
votes
0answers
1k views

Flask view dependency injection

so, first of all, I've been into trying to have a simple dependency container as possible in python and with your help managed to get conceive https://github.com/dareenzo/tinydic, many thanks. Now, I ...
7
votes
3answers
271 views

Builder/Wizard API for immutable objects

There are a lot of parameters I would like to configure for my Analysis object, so having some kind of composition helpers is a big thing to simplify proper use of ...
4
votes
1answer
131 views

List replication problem from Hacker rank

Problem: Given a list, repeat each element in the list n amount of times. Solution: ...
3
votes
1answer
330 views

Lazy, functional streams library for Node.js

I’ve written a small library that implements lazy streams in (ES2016) JavaScript for use in Node.js. The library could work in the browser as well with some minor modifications, but that isn’t ...
4
votes
2answers
89 views

Find the minimum number of operations (concat, add and subtract) for the numbers 1-9 to equal 100

I am beginning to learn Scala and functional programming, and I came across this puzzle. This looked like good practice and I have a solution but just want some hints in terms of functional approach ...
1
vote
0answers
22 views

Retrieve compilation files of smart contracts asynchronously via Ajax and add to database

I need to retrieve two files that are labeled :abi and :bin from a server. I then want to add these files to a database in a ...
2
votes
0answers
29 views

Test Driven Development in JS and Sinon Stub

I am going through some TDD and BDD tutorials which guide one through implementing a simple beverage-ordering system. While I think I understand the material, I am still wondering about some ...
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: ...
3
votes
0answers
76 views

Functional Merge Sort in Python with only boolean variables to control fall off logic

Merge Sort I have just implemented this merge_sort, and this is also my first algorithm implemented in Python, I am totally open to feedback about how to better use python. I am using Arrays instead ...
-1
votes
2answers
192 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: ...
3
votes
0answers
124 views

React.JS functional paradigm

I have some (minimal) experience with the functional programming paradigm and I'm new to React.js and reactive programming. I'm trying to get a flavour for the React.js philosophy and I keep seeing ...
2
votes
1answer
313 views

Grouping models without dictionary

I want to group an array of structs only using arrays into an array of new structs. In this example I want to group the Person structs by ...
4
votes
2answers
62 views

Implementation of undoable arrange (SendToBack, SendBackward, …) operations

I am developing a WPF designer where visual elements (rectangles, ellipses, ...) can be inserted, moved, resized and so on. Similar to a simple PowerPoint control. All the actions should be undo-able,...
1
vote
0answers
91 views

Purely functional minecraft-like mesh compiler

I'm creating a minecraft clone (for practice), in scala, using largely functional programming. When a chunk doesn't have a mesh loaded into VRAM, it create a Future for the vertex and index arrays, ...
1
vote
1answer
118 views

Parser Combinators in OO C

In trying to understand and use the Parser Combinator concept, I've coded up as close an analogue as I could manage within the constraints of the C language. C doesn't have first-class functions or ...
6
votes
1answer
496 views

Convert time 24hr format into time as words

I'm currently writing a Scala Object that converts time 24hr format (i.e. 00:00 - 23:59) into Time As Words (i.e. Eight o'clock, Half past eight, Quarter to nine etc). How can I refactor the current ...
1
vote
2answers
118 views

Find the most frequent character in a string

I'm trying to solve this problem https://community.topcoder.com/stat?c=problem_statement&pm=40 Given a string made up of ONLY letters and digits, determine which character is repeated the ...
5
votes
1answer
100 views

Drawing a regression line with a timeseries

My code is using seaborn to draw a regression line with a timeseries data as the x axis, and whatever you want the y-axis to be. Since seaborn does not support this function directly, a dummy column ...
-3
votes
4answers
763 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 ...
2
votes
1answer
88 views

Using partial application to compose functions

I have an application that will provide notifications to clients. It has two configurations: Default: A single web api instance that notifies the appropriate subscribers Alternative: Under high load,...
4
votes
1answer
970 views

Monad Implementation in Typescript

Having been introduced to monads through Scala, I am trying to add the generalized design pattern to my toolkit by implementing it in a language I use more regularly (typescript). My tests pass (...
2
votes
1answer
578 views

Implement array element swap in a functional language

Sorting algorithms involve swapping element positions in an array. This is my implementation of swap: ...
2
votes
2answers
513 views

Python - Random Number Guessing Game

I'm new to programming in general (Python is the first language I've tried learning) and I'm working my way through a collection of beginner's challenges. I'm having a little trouble wrapping my head ...
2
votes
0answers
52 views

R data.frame to function as.function.data.frame

I love relation and function. And I would love to move afap from one to the other. I've been looking for the function as.function.data.frame (or alike on tbl) but couldn't get it. The bells and ...
2
votes
1answer
43 views

Clear out a textbox after submitting its content

I struggled to figure out how to clear a textbox after submitting it's contents via a button control. I would like to know if my solution is an accepted practice for initializing a control after an ...
4
votes
1answer
68 views

CoffeeScript 2 + 2 program

I tested this program on Smooth-CoffeeScript I just wanted to have as many eyes on this as I could to learn about coffeescript; Is there anything I should do to improve it? Am I using the tools ...
2
votes
1answer
143 views

Euler #4: Refined Palindrome in Haskell

This is my attempt at the Problem Euler #4 in Haskell ("Find the largest palindrome made from the product of two 3-digit numbers.") ...
3
votes
3answers
265 views

Table builder pattern

Trying to combine functional style (immutable objects) and flexibility of property setters. For the sake of example, let’s say we have a soil types table with two attributes: Color and Name. I am ...
1
vote
2answers
82 views

Performant functional evaluation for enum value

I have a Java enum which represents the side of an order (enum Side {ASK, BID}) and I'm constantly writing code with which I'd like to use the ternary operator, e.g....
4
votes
1answer
185 views

Searching files in directory with various filters

Requirements Note: the requirements are invented by me for practicing functional programming. Functional Requirements Given a directory, all files below the directory (and its sub directories) ...
1
vote
1answer
55 views

Object comparison method as an example of using the functional style

I just started learning about functional programming, and thought I would have a look at writing a simple object comparer as the basis for my implementation. Below is my result. My assumption (in ...
4
votes
1answer
74 views

Refactoring an Object Walker utility function in Javascript

I'm refactoring some code, essentially a dot-notation walker for objects. I've abstracted things quite a bit, I'm to the point any more and I begin to loose readability. It all hinges on this one ...
13
votes
2answers
364 views

Complex scientific formula for nuclear magnetic resonance

I've been reading "clean code" tutorials, and I definitely see the value of using good names that "document themselves" to make intent clear. However, what can be done about complex formulas where ...
4
votes
1answer
83 views

Reduce namespaces

I have a collection of full type names where I need to reduce common namespaces. For this purpose I wrote two extensions. The first one explodes each namespace into pieces and the second one removes ...
4
votes
1answer
470 views

Functional Html builder

This is my third attempt to create a easy to use html builder because I wasn't really satisfied with the first one that wasn't extendable at all and even the one using dynamics wasn't much better. It ...
1
vote
1answer
238 views

Merge sort in declarative style with JavaScript

ES6 syntax helps to write code in a declarative style, which is exactly what I am trying to achieve here. Any advice to make my code "more declarative" (and easier to read) is welcomed. ...
2
votes
1answer
59 views

Mapping a user's availabilities

So we're starting to use Typescript for a new project at work. Part of the application allows a user to retrieve their future availabilities (present/absent/possibly present), for planning purposes. ...
2
votes
1answer
31 views

Fetch Keywords from comment and assign keyword id to comment

I have a small callback function which receives a comment in array like below: ...
5
votes
3answers
2k views

Functional Pascal triangle in Python (working version)

This is actually a follow-up question of Yet another Pascal triangle in Python written in functional programming pattern, which is put on hold for posting broken code. Again, this is my ...
1
vote
2answers
588 views

Finding the difference between two different arrays using JS and FP

I'm trying to practice functional programing using JavaScript. These pure functions just work together to find the difference between two arrays. I know that this might be an impractical example of ...
-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 ...
5
votes
1answer
572 views

Yet another Pascal triangle in Python written in functional programming pattern [closed]

Here is my implementation of a Pascal program, which is used to print an n-order Pascal triangle. This is actually an exercise I came up with to familiarize myself with Python's Functional Programming ...
5
votes
1answer
561 views

Refactoring away from exceptions

What do you use for refactoring away from exceptions while programming functional in C#? I defined this class to hold function outcome: ...
3
votes
0answers
286 views

Two reimplementations of the Underscore _.reduce function

I am working on rewriting the underlying code for some Underscore.js functions. Re-writing the reduce function has been causing a lot of headaches. I have been able to re-write it two different ways, ...
1
vote
1answer
100 views

Create a List of any type of object based on List of HashMap from JSON

I have this method that is working as i want: ...