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
5
votes
1answer
159 views

F# Idiomatic Log4Net Wrapper

I put together a log4net wrapper that more closely resembles F#-idiomatic logging functions. The basic idea is that there's a Log module that defines a set of 8 ...
5
votes
1answer
119 views

Combinatoric problem in Haskell

I am new to functional programming. Just now I solved my first "real world" task using Haskell and now I'm wondering whether I got it "right" and what can be improved. The problem arises from tensor ...
5
votes
2answers
410 views

Functional Conway's Game of Life in JavaScript

In this code, I tried to integrate my little knowledge of (and great fascination towards) functional programming. I'd like to make this code more functional, and faster, if that's possible. ...
5
votes
1answer
124 views

Project Euler problem 11, finding adjacent numbers with the greatest sum

The full description of the problem to solve can be found here. The code I have written works fine but seems extremely verbose for what it's doing, I'm not sure if list comprehensions are meant to be ...
5
votes
1answer
229 views

Popping from a list in state while a condition is true

I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling. To that end, I'm using ...
5
votes
2answers
2k views

zipWith function in Scala

My implementation works, but it looks very ugly. Curious to see how it's better implemented. The zipWith function takes a list of lists (...
5
votes
2answers
137 views

Beginner Project: Bunny City

I am a Java programmer, and I just recently started learning Scala for fun. I found a group of projects here, and I tried to do the graduation excercise. The problem is, my code looks a lot like java, ...
5
votes
1answer
61 views

Timeout Error in Fraudulent Activity Notification HackerRank

I am solving this problem: Fraudulent Activity Notifications on HackerRank. I am done with my code and is working, but it is inefficient as well for very large inputs. I don't know but after all ...
5
votes
1answer
142 views

Return the first recurring character in a string

The task: Given a string, return the first recurring character in it, or null if there is no recurring character. For example, given the string "acbbac", return "b". Given the string "...
5
votes
2answers
304 views

Implementation of Permutation Algorithm A from Topor, 1982

This is Algorithm A from Functional Programs for Generating Permutations (Topor, 1982). The author states that the algorithm was described in TAoCP Vol 1. We have implemented Algorithm A in F# as ...
5
votes
1answer
566 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: ...
5
votes
1answer
1k views

Battleship Game

Inspired by this question, I went on with the following version. My goal was to focus on pure functions, to avoid mutable variables and to be strictly functional. I have ignored the computer player ...
5
votes
1answer
272 views

Obtaining all repeated characters' position in a string using Java Stream API

Input is a string, and the method should return repeated characters in that string and the position of these characters. I'm currently using Java 8 Stream. The problem is I have to do it by calling 2 ...
5
votes
1answer
479 views

Python tokenizer in Haskell + Parsec

I wrote a tokenizer/lexer (difference?) for Python in Haskell: this is my code on GitHub. I already tested it out with some of CPython's standard library scripts, and it doesn't fail. However, it ...
5
votes
2answers
695 views

Typesafe Tic-Tac-Toe API

So I've been working on Tony Morris' Tic-Tac-Toe challenge. The rules are as follows: Write an API for playing tic-tac-toe. There should be no side-effects (or variables), at all, for real. The ...
5
votes
1answer
179 views

Pile shuffle of a vector

My goal is to simulate a Pile shuffle of a vector. It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle. As this is my first attempt at clojure code, ...
5
votes
1answer
405 views

How can I make this F# more functional?

I am currently learning myself a little F# and have written the following code to practice. The code uses the Mono.Cecil library to inject some IL at the start of every method in each .net assembly ...
5
votes
1answer
75 views

Currying in Lua

Just whipped up this quick curry function in Lua, as a building block for partial application and memoization. Any feedback is appreciated. It takes two arguments; ...
5
votes
1answer
83 views

Advent Of Code 2017 Day 4 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JavaScript only. So I took a problem from Advent of Code (the 2nd part of Day 4) You can only access the ...
5
votes
1answer
64 views

Python-like enumerate and join

I'm new to Rust and trying to convert some Python to Rust. I have the following in Python: ...
5
votes
1answer
217 views

“Guess My Number” with Racket

I am using the book "Realm of Racket" which was written by the people behind the Racket and Dr. Racket projects. It is a great book based on games, similar to the famous "Land of Lisp". The first ...
5
votes
1answer
75 views

String checking functions in functional JavaScript

Please review these string checking functions. This is the whole module which is actually written here. It supports buffer, array...
5
votes
1answer
503 views

Curry function with function constructor

Shall I make a curry function this way, or is it best to avoid Function constructor in all means? What I want to know is if this is "bad practice" and how else currying can be done. For instance, one ...
5
votes
1answer
412 views

Sudoku game logic

I am trying to create a Sudoku game in F# and I'm having a bit of trouble with the file reading and writing. But since I've also just started programming in f# I would like to check if my thinking is ...
5
votes
1answer
119 views

L system equations

This is my first program on my second try to learn haskell :) ...
5
votes
2answers
271 views

Checking in four directions for board game win

I have the following code which I would like to simplify in Haskell, although I'm not sure how. I recall that I can use monads to simplify a case chain when the result of the case leads onto a next ...
5
votes
1answer
522 views

Lightweight TicTacToe in F#

This is more of a 'model' of TicTacToe, as you'll see it's not "gameified" in the sense that it will allow for inputs and outputs nor will it record any "active" state of the game but those things are ...
5
votes
2answers
289 views

Project Euler 3: Getting the largest prime factor of a number

I'm looking for some general feedback on my solution to Project Euler challenge 3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? <...
5
votes
1answer
382 views

Algorithm to Iterate All Possible Strings in Clojure

I'm fairly new to Clojure and I struggled a bit coming up with a nice Clojure-y solution for implementing an algorithm for one of my applications. The real issue I'm trying to solve would require a ...
5
votes
1answer
646 views

helper method returning a call to itself

I wanted to eliminate some duplication and came up with something I've not seen so I figured I post it and see if others had. Using a delegate to allow the method to return another call to itself. ...
5
votes
1answer
779 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
5
votes
1answer
39 views

Typescript monad for data being loaded

I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
5
votes
1answer
263 views

Collecting YouTube links from a page

I wrote code for my needs (i.e. collecting YouTube links from a page) and it is simple, but now I just want to know what can I do just to make it a better and properly written one. For example, I ...
5
votes
3answers
68 views

Aggregate summary counts for an array of error objects

I'm doing some refactoring of someone else's code, and just want a second opinion, because of course I think my work makes it better, but some validation (or correction) would be helpful. Starting ...
5
votes
1answer
104 views

Compose n functions where the innermost function expects multiple arguments

I want to perform function composition like this: f(g(...(z(x) (y)); I have already compn: ...
5
votes
1answer
110 views

Option<T> functional type implementation and scenarios

Have you ever being implementing Option<T> functional type? It is discussed here. Basically, it is about using ...
5
votes
1answer
227 views

Binary to ascii mapping in JavaScript

This morning I've seen this on Twitter: http://mynewtechworld.tumblr.com/post/135545896048 I case that somebody can't see the image: I 01101100 01101111 01110110 01100101 you. Just for ...
5
votes
1answer
564 views

Conversion from decimal to negabinary and vice versa in Haskell

Recently I set about to writing conversion functions in Haskell between decimal and negabinary. I tried to write them in as much functional a style as possible, also aiming at brevity. Below I present ...
5
votes
1answer
665 views

Read text from stream char by char

I've started learning F# and functional programming in general, but the code I wrote doesn't seems to be really functional. Could you take a look and say how to make it more as it should be in ...
5
votes
0answers
74 views

Extending functions to tuples

Intro: Imagine you have defined addition on types A and B with function A add(A,A) and <...
5
votes
0answers
90 views

childrenCount function in old and functional styles [closed]

I'm trying to transition myself from my old coding-style (if-else, for.. in) to functional programming. I've tried to update the ...
4
votes
3answers
2k views

Sum of multiples of 3 or 5 using functional programming

I wanted to practice functional programming (fp) without using any library. So I took the 1st problem from project euler: If we list all the natural numbers below 10 that are multiples of 3 or 5, ...
4
votes
2answers
350 views

Detecting properly nested parenthesis using functional programming

So I have this code that is my attempt at a coding test from Codility. While my code produces correct results according to the requirements, (which unfortunately are copyrighted so I don't think I can ...
4
votes
2answers
860 views

Wrath Cookie Switch for Auto Golden Cookie Clicker

Sometimes you feel like a wrath cookie and sometimes you don't. Here is a function that I created that will run on an interval, so all I have to do is set a boolean when I want to switch between ...
4
votes
2answers
2k views

Password generator script

What I was trying to do here was create a Python script that would generate passwords with 16 characters with uppercase and lowercase letters, and numbers. The generated password would then write ...
4
votes
3answers
992 views

Cleaner way for coding a repetitive application of a function

I have this function definition which takes an r and applies the function f n times: ...
4
votes
3answers
102 views

Compare ZIP codes, disregarding leading zeros

I have a function that compares ZIP codes. It also has to handle cases where the input ZIP code be missing leading zeros, have extraneous leading zeros. This is what I've come up with. I don't have ...
4
votes
4answers
5k views

Calculating average grades

I'm a C# developer looking to learn more about Python and how to think in a more functional programming manner. I have the following which takes a series of grades and returns the average: ...
4
votes
2answers
161 views

ConsumingRouter to consume based on condition

Started as to make a stream splitter to split stream based on condition, but finally found that I did ConsumingRouter, to consume based on condition and while have to provide consumers before using ...
4
votes
1answer
32k views

Passing a generic function as parameter

Ran into this idea and I'm curious if it's possible. I'm trying to make a single function that can test ALL of my sorting algorithms dynamically. I want to be able to pass the sorting function as a ...