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
0answers
57 views

Synchronous logging of asynchronous retrieved folder info

I started learning functional programming with JavaScript and I have the basic idea of Functors, container types and etc. I was trying to experiment with arrays but I don't know how to solve the ...
5
votes
1answer
37 views

Generic memoize utility function for pure functions

Given the following generic memoize utility for pure functions with type hints: ...
3
votes
1answer
69 views

Updates or creates an entity based on if a value is present in an Optional

I need to get car info from a 3rd party web service and persist the data in my application DB. If my DB already has the car, I only update property values that may have changed. Otherwise, I create ...
4
votes
1answer
37 views

A library of 2D Shapes with functions for their intersections

The goal was as much code reuse as I could get. Shooting for a pure-function-y style. Would love any feedback on general architecture, adherence to standard practice and usability - as well as ideas ...
5
votes
1answer
104 views

Improving my Tic Tac Toe Solution in Scala

I'm relatively new to Scala and made a small TicTacToe in a functional Style. Any improvement options would be highly appreciated. There are some things which I am unsure of if they are made in an ...
6
votes
1answer
88 views

Taking n lines from a file which contains m lines, repeating the file lazily if necessary

The desire for such a function came out of the necessity of generating a "source" of Lorem ipsum by repeating over and over the same 50 or something paragraphs of the text. Actually I am ...
5
votes
2answers
93 views

Removing OO style coding from Haskell

Having coded in Objected-Oriented style my entire programming career, it's hard to adapt to functional style fully. I implemented a simple Hangman game: ...
5
votes
1answer
54 views

A simple reactjs form to calculate the liquidity ratio, daily cost of running, and days cash on hand

This is just a very simple form that tells you the liquidity ratio, daily cost of running, and days cash on hand of a company, given their current assets, current liabilities, and total expense of the ...
3
votes
1answer
88 views

Improvements, TicTacToe in Scala

I've just started my journey into functional programming and tried to implement a TicTacToe game Recursively without State in Scala. What I dislike is the JOptionPane but I don't know if i can solve ...
1
vote
1answer
70 views

JavaScript — Convert decimal to another base

The Source code is maintained on GitHub and may be cloned via the following commands. A Live demo is hosted online, thanks to GitHub Pages. ...
1
vote
0answers
40 views

Adding common Python functions to JavaScript

I have written a few classical Python functions in JavaScript. I would appreciate any kind of feedback. The main goal is to learn about JavaScript. For example errors, improvements or existing ...
3
votes
1answer
99 views

Hackerrank problem: Climbing the Leaderboard (Java)

I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
2
votes
0answers
20 views

Writing an idiomatic task-tracker in Racket

I'm trying to learn Racket. I'm coming from a mostly imperative background, but I do have some casual experience using functional languages like SML and working with lists and recursion for small ...
3
votes
1answer
91 views

C++ algorithm to implement multiple operators in one

I have a class called IntMatrix which has 2 fields: ...
-2
votes
1answer
26 views

Node.js ws server: global or local functions? [closed]

I'm working on a Node.js chat app project using the ws library. I have it up and running but I'm still making improvements and adding stuff like authentication, etc....
2
votes
0answers
25 views

My implementation of Clojure's assoc-in

This is my implementation of Clojure's assoc-in function. I am looking for tips on making it more idiomatic and in general, better. ...
5
votes
1answer
69 views

Caesar Cipher [The Odin Project-Javascript Exercise]

Very new to coding, so please don't bully me. Implement the legendary caesar cipher: In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, ...
1
vote
1answer
46 views

Basic tic-tac-toe matrix in Haskell

Beginner functional programmer... (but not beginner programmer) Currently, I have the following code: ...
1
vote
1answer
46 views

Functional Python Script to write a large amount of CSVs to database

I just finished up this script that crawls hundreds of local git repos for csv files and then stores them into a database. I've tried to follow a "functional" paradigm for this script but am kind of ...
1
vote
1answer
29 views

Ruby Exercise: Implement your own “#group_by” method

Task: "Implement a method 'gruppiere', in a way that it can be invoked on all enumerable objects (Enumerable). The method receives a block and returns a hash. The items of the enumerable a grouped ...
2
votes
0answers
37 views

Longest Substring Without Repeating Characters in ReasonML/Ocaml

LeetCode Problems 3. Longest substring without repeating characters Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
7
votes
1answer
225 views

Decorator to cache a function result for some time

I recently played around with a script that got some data from the Google API. As I didn't want to spam requests at the service (and potentially get blocked), I made this decorator, which caches the ...
2
votes
1answer
37 views

Efficient Implementation of functional and Lazy evaluation in C++

I am creating a c++ library implementing Java Functional Programming alike interface. In short, the code will look like this: ...
3
votes
2answers
104 views

Creating a new list using a stream

I have a StudentSchedule class that contains schedules of a student, the student may switch between rooms over time. There's no overlap with the date ranges so if a student stops at 2020-01-01 the ...
1
vote
1answer
92 views

Is the JavaScript code I've provided following Functional Programming best-practices?

I'm trying to wrap my head around JavaScript Functional Programming. I have created a very basic script that creates a new elements and appends them to the DOM. If anyone could share any feedback, ...
-3
votes
1answer
39 views

Printing the steps of a function composition

I have this code: ...
1
vote
0answers
68 views

Does Subscribe sound as a right name?

So I have a Know Your Customer provider interface like this to estimate risks associated with a customer: ...
3
votes
2answers
110 views

Leap year check in Java (functional style)

I have done the leap year check on https://exercism.io already in a lot of languages. Today I came back to the exercise in Java and was playing around with some maybe more funny ways to do the check. ...
3
votes
1answer
51 views

Maximum distance between space stations HackerRank

I am just working on Flatland Space Stations problem, and it is not seeming to be a tough question, but my algorithm lags in some aspects, since it solves majority of the test cases but fails for some....
3
votes
1answer
45 views

Scala: Cumulative String Tokenisation

I'm trying to split an incoming stream of strings into cumulative tokens per line item using a function below, ...
2
votes
0answers
28 views

Decoding request object before use it in an Insert query

I want to decode a request object before use it in an insert query. Request object containes the following JSON body: ...
2
votes
1answer
25 views

naive bayes sentiment analysis classifier in clojure

attaching my try on implementing simple naive-bayes classifier for sentiment analysis as part of learning clojure and using functional programming on ML algorithms. I tried to invest more time in ...
3
votes
1answer
95 views

Writing pure functions but have a chain

I'm trying to play around with Godot to learn C# and I was trying to creating pure functions to do the velocity, but I found I was repeating myself. ...
5
votes
2answers
88 views

Bloom Filter in Haskell

I recently implemented a Bloom Filter in Haskell and, although I am not new to functional programming, I am a beginner when it comes to Haskell itself. I'll gladly take any feedback regarding the ...
1
vote
1answer
83 views

Functional Utility in C++ (Curry, Partial Binding and Pipeline)

TLDR I created a curry/partial binding "lib. My request for "code review" is, what possible improvements I need to achieve "release quality", if I wanted to release this as a lib? You can see the ...
1
vote
1answer
38 views

Name for mconcat implementation for applicative monoid

I have implemented a function mcollect which is effectively mconcat only for applicative monoids: ...
2
votes
1answer
39 views

Re-write custom feature encoding function python

I have a question regarding code quality and best practices. My task - to write a feature encoding function that will encode categorical labels, boolean labels as one-hot encoding, timestamps for ...
3
votes
1answer
64 views

Longest Substring without Repeating Characters Problem - Kotlin Recursion

I am practicing coding questions on leetcode. I have been an OOP my whole career, and I am trying to wade into the dark abyss that is functional programming. So I am trying to do things purely ...
0
votes
0answers
47 views

Implementing Currying

I'm trying to learn functional programming (using Javascript), so I took a stab at implementing a curry function to properly grok it. Here's my code: Curry.js ...
3
votes
1answer
125 views

Write a wrapper to REST API with asyncio

I want understand how to correctly structure a functional asyncio-based program. The code below wraps two external APIs to provide the client a simple ...
2
votes
0answers
87 views

“Rock, Paper, Scissors +” in F#

During a discussion in a development chat, a user suggested to another (in the context of C# originally), UserA: Challenge: Create an implementation of RPS, and then show how it can be extended to ...
2
votes
0answers
149 views

generic implementation approaches for a recursive function

Let's take the famous fibonacci problem as an example but this is a generic problem. Also, taking scala as the language as it's rather feature-rich. I want to know which solution you'd prefer. we all ...
2
votes
1answer
64 views

Trying to convert imperetive code to functional -Haskell

I'm very new to Haskell and I was trying to implement a DFT which is very imperative into Haskell and I wanted to get a feedback. More specially how can I avoid so many helper functions and I avoid ...
1
vote
2answers
86 views

A function to scan user input as string

I know that multiple functions are already available. However, I thought of writing my own because I wanted to learn the logic (and also because I thought there wasn't enough confusion :P). Please ...
5
votes
1answer
92 views

Program for calculating and ranking scores

I've recently completed a vanilla JS challenge . It is a method for calculating and ranking scores. If possible, I would love to make it better. Any suggestions are welcome. Challenge Directions: The ...
-2
votes
1answer
53 views

python - class not returning the expected result. I am using function and a class [closed]

I am trying to pass 2 values from a function to the class and get a result from the class. For example, if I send value "dog" I should get the result as "dog runs" as a returned result. Need help with ...
3
votes
0answers
41 views

Functional Dependency Injection Abstraction

The F# web-development framework Giraffe supports a functional style of Dependency Injection using a form of the Reader monad, as explained in this GitBook. I would like to use this pattern more ...
1
vote
1answer
54 views

Clean up function in Javascript Event Listener

I am trying to refactor a chess game I am currently creating so the code is more flexible and maintainable, while doing this, I came across an event listener which I have no idea on how to make "...
0
votes
1answer
44 views

Functional vs Object Oriented Approach for UI codes

I have the following snippets. which formats error messages based on a map. I can do it as a simple function call the function for transforming the error. or create a class and handle it in that way. ...

1
2 3 4 5
18