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

How to check if a string is null and use its value avoiding NullPointerException in Java [closed]

I need to map few object's properties to another object but those properties could also have null values. This can cause NullPointerExceptions that can be avoided using this code: ...
2
votes
2answers
63 views

Cyclomatic Complexity (complexity)

I have a program for finding shortest distance/path and I got a correct answer but I am getting an issue i.e., "Function 'shortestPath' has a complexity of 9. Maximum allowed is 6." This is ...
0
votes
0answers
33 views

Using inspect.signature with higher order functions in Python: good practice? [closed]

Consider a function that accepts a Callable as a parameter and a dictionary of arguments as another then simply applies the parameters to the function: ...
5
votes
3answers
577 views

await user input with async/await syntax

for clarity: moved here from stackoverflow after being pointed to Code Review being the better place for this question I love async/await and Promises since I got my hands on them. And I might be ...
1
vote
1answer
62 views

Poker Hand Evaluator in Haskell

The idea is to represent a hand as a list of cards and create a frequency mapping, which can then be used to identify what rank of hand you have and arrange your hand in a way that allows the Ord type ...
2
votes
0answers
22 views

Splitting a list based on a delimeter into n chunks in Haskell. How can I write my functions more effeciently?

Split: Write a function split that takes a delimiter value “c” and a list “iL”, and it ...
6
votes
3answers
1k views

Counting words from stored .md files

The following searches recursively for all the .md files inside a folder. It then stores the text of the files in an array. Finally, it sums their word count using ...
6
votes
4answers
1k views

Convert minutes portion of time to decimal

I am making an hours calculator app. It takes a start time, end time and time taken for lunch. For the start and end time it takes a four-digit hh:mm time. For example, 10:20. I have made a function ...
2
votes
1answer
48 views

Keep reading user keyboard input if available, while echoing back the latest available

On StackOverflow I have asked a question a few minutes ago, but then by trying a bit more, I found the answer myself, and I'm posting the resulting working code here for review. What the code does, is ...
3
votes
1answer
72 views

Haskell-like function composition function

Much like this question I'm attempting to write in C++ something which can resemble Haskell's (.) function as much as possible, which is basically Chapter 1's ...
2
votes
1answer
63 views

Projecteuler.net Problem 2 using collection pipeline Pattern

I solve projecteuler.net Problem 2 deferent way Generate number from 1 to range ex 100 and get the even number Get Fibonacci numbers from list Reduce array I have one problem with a large set of ...
2
votes
2answers
61 views

HackerRank - Filter huge list for elements that occur more than a given number of times

I'm trying to solve this problem on HackerRank, which basically requires the solution to read an input like this (comments are mine) ...
3
votes
1answer
38 views

Showing values from different fields in an array with ternary

This small piece of code shows the value of different fields of an array. I'm looking for a way to improve this nested ternary function. An if statement solution ...
5
votes
3answers
670 views

Finding even or odd numbers

I'm looking for critiques to see what I could have done better or different ways I could approach writing a script for finding even or odd numbers. I am new to programming with JavaScript, and ...
5
votes
1answer
84 views

Converting duplicate JS code into a higher order function

I have a block of code that is re-used and I want to use functional programming to remove this duplication. My code takes an array of items, splits the items into batches of 500 and then does some ...
4
votes
0answers
85 views

This recursive function encrypts a string

Is there a way to rewrite these last 2 recursive functions with fewer arguments (preferably 2) while keeping them recursive? The entire code can be seen here: https://github.com/GirkovArpa/hutton-...
7
votes
1answer
82 views

Mutual recursion - Naming the opponent serve - pingpong

Problem statement Ping-pong The ping-pong sequence counts up starting from 1 and is always either counting up or counting down. At element k, the direction switches if k is a multiple of 7 or ...
5
votes
1answer
81 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 ...
6
votes
1answer
74 views

Generic memoize utility function for pure functions

Given the following generic memoize utility for pure functions with type hints: ...
3
votes
1answer
74 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
46 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
147 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
106 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
119 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
55 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
95 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 ...
2
votes
1answer
75 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
41 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
213 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 ...
11
votes
5answers
1k views

Vue.js search functionality

In my BlogList.vue component I made a search input field: ...
3
votes
1answer
92 views

C++ algorithm to implement multiple operators in one

I have a class called IntMatrix which has 2 fields: ...
-2
votes
1answer
27 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
36 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
124 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
52 views

Basic tic-tac-toe matrix in Haskell

Beginner functional programmer... (but not beginner programmer) Currently, I have the following code: ...
1
vote
1answer
47 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
36 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
248 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
38 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
107 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 ...
2
votes
1answer
106 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
114 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
66 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
29 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
29 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 ...

1
2 3 4 5
19