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
2
votes
2answers
476 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
128 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
251 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
54 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
72 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
361 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
408 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
219 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
58 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
562 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
65 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
571 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
519 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
275 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
97 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: ...
6
votes
0answers
300 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
8
votes
2answers
142 views

Functional way to have two toggles that turn each other off

I have two sets of toggles that need to "uncheck" each other. This is my current solution which is working. Can it somehow get more functional/elegant? ...
3
votes
2answers
613 views

Summarizing the score of a personality quiz

This function takes a list of questions and list of answers provided by the user. The list of answers is always a list of booleans (for true and false) and the list of questions takes the following ...
1
vote
1answer
58 views

Function that takes an object and a query obj that tries to regexp matches its values

I have the follow matcher method that should do: ...
6
votes
2answers
307 views

Coin Change Kata in ImmutableJS

I'm preparing for a job as a junior/intermediate JS developer. I'm comfortable with my ability to think in higher-order functions, but less confident in my syntax and style (I have more experience in ...
1
vote
2answers
72 views

Proper use of tail recursion while forming a list

As a project to better develop my understanding of functional programming, I am writing a prime number generator in Scheme. I am using a simple brute-force algorithm to detect whether a number is ...
0
votes
1answer
866 views

Converting a 2D array to a JSON list

I am wondering if I could implement this in a cleaner, more elegant, strictly functional way: ...
-2
votes
1answer
2k views

parking lot program in Java (BlueJ) [closed]

The program is as following - ...
5
votes
1answer
99 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: ...
2
votes
0answers
94 views

Set manipulation (javascript arrays) using lodash

I'd like a more elegant and readable (if possible using functional programming style) for collection filtering (groupToAdd and groupToDelete collection handling) Just getting rid of multiple _....
1
vote
0answers
132 views

Simple INI and command-line parsing, functional programming edition

I'm in the beginning stages of rewriting the model layer of my VBA Sync Tool in F#, to better learn functional programming. So far I've defined: A public ...
2
votes
1answer
183 views

Functional API wrapper written in Scala

I've been working on an small API wrapper for the GitHub API using Scala (full source on GitHub). I'm still very new to the language, so I was hoping to get some feedback about a couple of design ...
1
vote
1answer
80 views

Parsing string into hash-map with 2D coordinates as keys

I had never programmed in a functional programming language before. I think that this function has large nesting. Is there way to rewrite it better? I am most worried about the use of "flatten". Is ...
14
votes
4answers
2k views

Create a function with an undetermined number of successive calls

As part of a programming challenge, we are tasked with creating a function with an undetermined number of successive calls. As an example, let's say the function returns simply the sum of the provided ...
10
votes
1answer
864 views

Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
1
vote
1answer
43 views

Nesting elements in a shallow hierarchy

I wrote some code to generate list items for a menu in Clojurescript. The intention is that the code takes parsed Markdown (Hiccup) that has been filtered down to h2...
4
votes
1answer
135 views

Pattern matching a ZMachine

Anyone following Eric Lippert's blog will know that he has an on going series where he is building a ZMachine in OCaml. C# 7 is another step forward in adding features normally found in functional ...
5
votes
0answers
299 views

A* Algorithm in F#

Inspired by this post I looked up A* on wikipedia and went on with my own implementation as seen below where I try to mimic the pseudocode on Wikipedia but in a recursive manner. I would like any ...
5
votes
4answers
224 views

Remove contiguous elements in array in a more functional way

I try to remove elements in an array if the number of contiguous element is greater than two. Here are the tests: ...
3
votes
1answer
87 views

Numerical streams example

I am reading "Java 8 In Action" (by Raoul-Gabriel Urma, Mario Fusco and Alan Mycroft), section 5.6.3, pages 116 and 117. The code that is presented handles calculating so-called "Pythagorean Triples". ...
0
votes
1answer
44 views

How to better organize the declarations of these functions?

So as I understand it, you should always declare a function before it gets called. However in the code below, how could this be restructured so that this philosophy is satisfied? ...
-1
votes
1answer
811 views

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
4
votes
2answers
112 views

Return the indices of the two numbers such that they add up to a specific target

(...as I learn Kotlin) I want to get the indices of the two numbers such that they add up to a specific target from a given array of integers. Solution: ...
4
votes
1answer
238 views

Christmas Tree in Kotlin

Please review my code for printing a Christmas Tree. The idea was to merge some functional programming ideas (immutability, streams) and OOP (every thing is a small object). I'm looking for a review ...
1
vote
1answer
23 views

Use only necessary fields in an object for URL params

I'm trying to cleanly grab some fields I need from an object. The scenario is this: I've got an object that is stored with certain 'extra' properties that exist because of the way we've set up our ...
3
votes
1answer
80 views

Transformations an array, combination of between map and reduce

I'm working on a function that reduces pairs of elements if they meet some criteria. For example, given an array: ["1", "2", "a", "b", "3", "4"] I want to ...
6
votes
2answers
230 views

Navigating a bounded 2D list (Advent of Code, Day 2: “Bathroom Security”)

I'm trying to solve the following Advent of Code problem in F# for practice. Description of problem (can be found here): Basically, there's a 'key pad' that I need to figure the combination to. To ...