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
1 answer
31 views

Meta Collatz Sequence

Context Chapter 6 of Learn You A Haskell contains a function called chain, which outputs the Collatz sequence of a given input. (In short, it takes a natural number....
  • 798
1 vote
2 answers
170 views

Simplify a function which performs manipulation of data in Javascript

Upon suggestion in the original question within Stack Overflow, I'm bringing my question here. We have created a function that will convert the data into the desired format, but it has a lot of code ...
  • 113
1 vote
1 answer
29 views

Random ladder for public-key encryption

...
2 votes
1 answer
55 views

Project Euler 11 Haskell - Largest product in a grid

Intro I have been learning haskell and functional programming using random Project Euler problems. Currently, I have solved Problem 11. What is the greatest product of four adjacent numbers in the ...
3 votes
2 answers
84 views

MP3 Playlist Class in Python

Background Info I am an intermediate level Python programmer. This is my implementation of a MP3 Playlist class challenge that was hosted on 101 Computing.Net. The ...
  • 131
2 votes
1 answer
90 views

Commented Parser Combinators in Lisp-style C

I've attempted to remedy the issues outlined in the answer to my previous question. I've added several hundred blank lines to better illustrate the grouping of functions and generally make things look ...
  • 1,948
2 votes
1 answer
118 views

Parser Combinators in C redux

A few more rewrites down the line from my previous question, this is the C version 11 based on the PostScript prototype version 12. The PostScript version is shorter, but it's some crazy ass ...
  • 1,948
1 vote
0 answers
39 views

Reusable and testable JavaScript code for URL fragment-based tab navigation logic

Foreword As a personal project, I've been creating a SPA blog (available here), which features 4 tabs (Thoughts, Projects, Readings, and CV), each accessible via one of four radio buttons, and several ...
  • 507
1 vote
2 answers
70 views

UPDATE on Newspaper Bill Calculator CLI with Python (1 of 3, Core)

Code is posted after explanation. Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused. Post 2 of 3, CLI: UPDATE 1 on Newspaper ...
1 vote
0 answers
40 views

Testing whether one interval overlaps other intervals

I recently started to learn functional programming and wan't to know If I'm doing things right. I use @effect-ts/core lib as well as ...
0 votes
0 answers
69 views

Functional Fibonacci in OCaml

I'm very new to OCaml, and as an exercise I decided to implement the nth Fibonacci algorithm (return a specific Fibonacci number, given an index) in different ways, using what I've learned so far. I ...
  • 729
2 votes
1 answer
80 views

Newspaper Bill Calculator CLI with Python (1 of 3, Core)

Code is posted after explanation. Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused. Post 2 of 3, CLI: Newspaper Bill ...
1 vote
1 answer
107 views

Convert from get response to array of type

I would like to know if this is the best/most efficient/industry standard way of converting from the http response to an array of typed values: Type class: ...
  • 157
0 votes
1 answer
107 views

Fizzbuzz Solution - complexity, readability, performance, lines, obfuscation... - .sort()

The fizzbuzz challenge presents a lot of interesting questions for 'intermediate' programmers like myself. I have found that I don't actually know where to draw the line with, complex (hard to read ...
  • 111
4 votes
1 answer
183 views

Haskell: implementing Read for a custom dynamic value type

I'm using Haskell to interpret a dynamically-typed language. I have a sum type called Value which can represent some basic objects: ...
  • 143
1 vote
1 answer
145 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
2 votes
1 answer
91 views

Stream Partitioner

Discussion I've been trying to increase my knowledge of Java Streams and for practice, I devised up the requirement of partitioning a Stream of values into a ...
  • 1,835
4 votes
0 answers
164 views

GeekTrust: Traffic problem - functional programming

First attempt to write functional programming, been following OO paradigm all through my programming journey Please review the code and let me know if any comments and violations of functional ...
2 votes
2 answers
92 views

A Union Data Type

Introduction I'm trying to get familiar with functional programming by implementing some functional concepts. One of these concepts that I've attempted to implement below is a ...
  • 1,835
5 votes
1 answer
110 views

Validate Finnish IBANs

I am currently studying an online course in Haskell and there are no "model examples" of the assignments after finishing them. I'm slowly getting the hang of this, but I'd like some feedback ...
  • 87
-1 votes
1 answer
136 views

Refactoring this code into OOP & less functional programming

I got feedback from an interview test where they wanted me to prove that I've got a grasp of OOP php programming. This file especially I got feedback on that it's more functional than it is Object-...
  • 11
1 vote
1 answer
45 views

functor chaining function for c++20

How might chain_apply() be improved? ...
  • 1,394
3 votes
0 answers
201 views

Command line wordle

I am seeking a review of my command line wordle game. Having only recently started exploring functional programming, I expect that there will be no shortage of areas to improve. This is my first ...
3 votes
2 answers
551 views

Download entire localStorage as file

I would like to download the entire contents from localStorage to a json file (in a "clear" formatting). I've tried this and it works perfectly. However, ...
0 votes
0 answers
93 views

Project Euler 1, 2 and 3: Functional Programming style using F#

After doing about 50 Project Euler problems in my "native" language (C#) I decided to redo some of the problems I did many years ago in F#, as it's a language I always want to give a go. ...
3 votes
0 answers
20 views

Ocaml add index to every item of a collection

I want to add a unique ID to every element in a collection (before output it as a JSON object). A collection can be any set of items, as long as it has a map method ...
  • 983
4 votes
1 answer
138 views

Functools extension library

I wrote a utility library inspired by functools that adds some common operations on functions I frequently use in my projects. As usual I'd appreciate any feed back....
0 votes
0 answers
23 views

make an array of cells from formula like in excel with javascript?

I'm working on stylesheet in Excel, and I've made this function of makeCells is there a better way of doing it. I've tried regex to get two cells ...
3 votes
1 answer
133 views

Efficiently calculating perfect powers in Haskell

I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell The number 81 has a special property, a certain power of the ...
3 votes
0 answers
169 views

Advent of Code 2021, Day 3 in Haskell

This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal. ...
  • 131
2 votes
2 answers
466 views

Improving the Conway's Game of Life Code With Functions in Python

This query is a part of Conway’s game of life. Currently, this program takes about 70 lines of code in Python to return the functionality of the game, which can be simplified to fewer lines of code ...
  • 37
0 votes
2 answers
74 views

Processing list of users- filtering out from refused list

The code below takes a list of users and displays two lists Refused users Admitted users Sample output: Refuse: Phil, Lola. Admit: Chris, Anne, Colin, Terri, Sam, Kay, Bruce. Any feedback is ...
  • 602
1 vote
0 answers
33 views

Relational join of two datasets

Front Matter I'm learning Scala and have not gotten used to functional programming and the language. I'm hoping a review of my naively implemented code can help me bridge my object-oriented ways to ...
  • 111
2 votes
3 answers
144 views

Finds Keywords in Log Files

This is my first project in C and I wanted a more experienced person's insight on how I made the whole program. Just looking for feedback it works how I want it to. The Github is here. Thank you so ...
  • 21
1 vote
0 answers
47 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
  • 141
0 votes
0 answers
62 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
  • 101
2 votes
0 answers
76 views

Download and parse XML data from a URL every minute with F#

The purpose This code is intended to achieve the following goals:- Create a hard coded list of lifts, this is pretty static and I add some extra info so I'm ok with this being in the code but I may ...
0 votes
0 answers
91 views

Gilded Rose with pure functions in C#

Gave myself the challenge of solving the Gilded Rose with pure functions in C#. All one-line lambdas, all static, all the time. The original kata assumed the code would mutate the given array-- I've ...
  • 216
2 votes
1 answer
99 views

Garden simulator [closed]

I tried to write the program so that it runs without error but I want to improve the program so that it follows the Single Responsibility Principle. What changes can I make to improve this program? I ...
  • 21
4 votes
1 answer
415 views

Is there a better way to apply a filter over an Either right value?

Suppose you have an IO (Either String (String, [Int])) and you want to filter the [Int]. Let's say we want to use the following ...
5 votes
1 answer
560 views

Reading a CSV file using Haskell

I'm reading a CSV using Haskell. I'm not sure if this is the appropriate way to do it. This is what I'm doing: Read rows from a CSV -> return lazy byte string Parse the headers and rows from the ...
1 vote
3 answers
75 views

Word frequency finder

Challenge: find the top three most frequently used words in a string. Only imports from the base package are allowed (source: codewars) I'm looking for feedback on (...
  • 155
3 votes
2 answers
99 views

Split string at given positions

Given a vector <Vec<usize>> of indices indicating where to split a string as follows: ...
1 vote
0 answers
26 views

TypeScript generic higher-order function returned function returned type

I have a higher-order function to create another function given a regular expression: ...
5 votes
1 answer
111 views

Small combinator parsing library in Haskell

I recently wrote code to parse lambda expressions written in a lisp like format, using a small hand-rolled parsing library. The goal This code was written as a part of this code-golf challenge not as ...
0 votes
0 answers
32 views

Refactor Javascript filter that handles click and changing together dropdown filters

I'm looking to rework and make it easier to read this handleFilterChange function This is helper being used in the function ...
-2 votes
2 answers
102 views

Getting items that have more than one entry in the array with optimized code

...
  • 123
2 votes
2 answers
309 views

piping a std::tuple into a function

This is a mythical beast we discussed in a previous question: ...
  • 1,394
3 votes
1 answer
77 views

garbage string remover with array or object input

This is the second time I am writing any practical JavaScript so it is pretty likely that I have messed something up. I am beginner, so just need a piece of advice before sharing the code: Do I need ...
0 votes
1 answer
58 views

Cardinal to ordinal numbers in F# code reuse

I've been experimenting with the F# Bolero environment to learn F# a bit and I was trying to get the hang of pattern matching by generating ordinal numbers (1st, 2nd, 3rd, ...) from cardinal numbers (...

1
2 3 4 5
21