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.
2
votes
1answer
31 views
Sum an array of video lengths in JavaScript into HH:MM:SS
I am trying to learn functional programming in JavaScript, and saw a little task on Twitter that I wanted to have a go at:
...
2
votes
1answer
41 views
AngularJS code to query DB and update $scope
I have an AngularJS function that is used to determine which $scope associative array variable is to have data pushed into it. I would love to be able to remove the ...
0
votes
0answers
26 views
Early-termination foldLeft for Scala Streams
The foldRight and foldLeft methods for Scala Streams cannot terminate early, so here is my ...
1
vote
2answers
43 views
Prime factor tree
Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is ...
5
votes
1answer
79 views
1
vote
1answer
43 views
Map all symbols in module to dictionary
The div and add functions are located randomly in my package structure. I have a function with this signature:
...
3
votes
2answers
30 views
Bubble sort in Scala
I wanted to implement a bubble sort in Scala following the steps described in: http://www.bbc.co.uk/education/guides/z22wwmn/revision/3
...
1
vote
2answers
52 views
Scraping and using JSON data from thousands of files in a directory
I have a few thousand json files containing order histories sitting in a directory from one of our systems. Since customers can opt in to receive marketing I'm opening each json file and then ...
2
votes
2answers
37 views
Summations and products, and factorials oh my
The proper title of this question should be "Summations and products, and factorials oh my!".
After getting quite a bit of useful feedback on this question from @mjolka, and a comment, I decided ...
0
votes
1answer
32 views
php most elegant function call returning array [closed]
I am asking your preference between two similar solutions.
First way :
...
4
votes
2answers
104 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 ...
3
votes
1answer
55 views
Trying to do Type-Driven Development in F#
I've been wanting to try out F# for some real world programming so I decided to try rewriting a program that is being used at work.
It can be reduced to a few steps:
Get report templates.
In this ...
1
vote
2answers
52 views
Number to german decimal format converter function [closed]
I have a function that formats a number (even a float) to a German decimal format. I got this function from here ...
2
votes
1answer
42 views
Summations and products in F#
I was bored, and looking to do something that involved anonymous functions, and it was suggested by @Quill, that I create a summation function. I decided to also include a product function as well to ...
4
votes
4answers
89 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:
...
1
vote
0answers
46 views
2
votes
1answer
51 views
Golden Section Search in Lisp
I implemented the golden section search algorithm recursively in Lisp. My code is:
...
7
votes
1answer
86 views
Functional-style list in C++
I've implemented a functional-style list structure in C++. It seems okay so far, and doing custom allocation for list nodes improves performance greatly. I omitted that part here for simplicity.
The ...
2
votes
1answer
116 views
Functional pattern matching in C#
I recently read a really interesting post on adding functional pattern matching to C#. Here's a quick and dirty implementation using delegates and dictionaries.
Right now, I require that ...
0
votes
2answers
55 views
Reducing Repetitive Code
Originally, I was going to post a question about how to condense four repetitive functions ( https://jsbin.com/pufizo/edit?html,css,js,output
) into a single function, but I wound up figuring it out ...
4
votes
1answer
63 views
Extending SeqLike - move an element to the front of the sequence
I wrote a method called bringToFront, which moves an element a to the first position of a sequence ...
6
votes
0answers
74 views
Small game written in F#
I'm trying to wrap my head around F#. I'd like your honest opinion about this simple game source code that I wrote. Rules are simple:
Every player has soldiers and territory
Player can recruit ...
1
vote
2answers
99 views
Generate code from full name and index number
Does this script look well-written and formulated?
...
13
votes
1answer
228 views
Clojure Minesweeper from scratch
In order to exercise and learn Clojure, I decided to write a simple Minesweeper game from scratch. I'd consider myself as a Clojure novice and would be thankful if somebody could do a review or give ...
3
votes
3answers
77 views
Optional Consumer for ifNotPresent
As Optional have only ifPresent and not have another function to be run in false case so I did the below class for that, please check it and give me your feedback:
...
1
vote
1answer
69 views
Routing Java objects using conditional consumers
As per a previous question here and answers I got, I used it to get a new implementation. I found that I have to make two implementations match once "to ignore other consumers after matching once" and ...
3
votes
2answers
75 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 ...
2
votes
1answer
94 views
Project Euler 4 The Functional Way
I'm learning Scala (and functional programming). Is there a better way to solve Euler problem 4 than either of these two solutions.
Euler 4
I like this array comprehension solution, but it wastes so ...
2
votes
1answer
30 views
Lattice traversal functional algorithm
I have the following code which returned the solution I was wanting after running for 1 hour. Are there any techniques I could use to improve run-time?
If I were using imperative programming I would ...
5
votes
3answers
108 views
Funny string python solution
Problem Statement
Suppose you have a string \$S\$ which has length \$N\$ and is indexed from \$0\$ to \$N−1\$. String \$R\$ is the reverse of the string \$S\$. The string \$S\$ is funny if the ...
2
votes
1answer
51 views
Utopian Tree in F#
This is the Utopian Tree in F# (from HackerRank)
The Utopian tree goes through 2 cycles of growth every year. The first
growth cycle of the tree occurs during the monsoon, when it doubles in
...
1
vote
1answer
26 views
MonoAlphabetic and PolyAlphabetic ciphers in Haskell
This code defines functions to cipher text with both mono-alphetic (Caesar) ciphers and poly-alphabetic ciphers. I also define a shortcut for rot13. I like this code and I think it is easy to read, ...
3
votes
2answers
66 views
N-queens problem in Haskell by bruteforce
I wrote a Haskell program to solve the N-queens problem by bruteforce. It works and I find it reasonably readable
But it is pretty slow:
5 seconds for one solution of 8 queens.
1 minute for one ...
4
votes
1answer
64 views
Implementing the basic elements of functional programming with C++ templates
With C++ templates, I've implemented a template list type with cons, reverse, merge, sort, filter, map, fold; and higher order template functions with currying. The C++ compiler can also work as an ...
4
votes
2answers
51 views
Print the length of words as input as a histogram with horizontal bars
Input
A list of words separated by any number of spaces.
Output
A horizontal ASCII art histogram, where the n-th line is composed by as many asterisks (*) as the ...
5
votes
1answer
73 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 ...
4
votes
1answer
68 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 ...
4
votes
1answer
81 views
HackerRank - Candies
Here is the solution I've written for Hacker Rank Candies challenge.
It uses dynamic programming (memoization in a boxed array).
I'm interested on what could be done to improve this code in term of ...
3
votes
1answer
115 views
6
votes
1answer
91 views
Hello Functional World: Counting occurrences of each letter
Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps.
I set myself a simple challenge to count the instances of each ...
5
votes
2answers
356 views
Mock/Stub out filesystem in F# for unit testing
I'm looking to do some basic verification testing on my functions that write to the filesystem.
I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
6
votes
3answers
96 views
Number of Chocolates to Gluttonize in Clojure
I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters:
...
1
vote
2answers
53 views
3
votes
3answers
141 views
Creating an array of objects for dictionaries
I wrote a piece of code that creates an array of objects based on the array of dictionaries. The problem is that my solution uses multiple loops imperatively.
Let's consider the following case. There ...
6
votes
1answer
65 views
Equilibrium Index Implementation
I have come up with a solution to the equilibrium index problem with help from the answers off here:
...
1
vote
1answer
80 views
5
votes
2answers
140 views
Reading input from console in F# (as a sequence of lines)
Consuming input line-by-line until the end is often useful. In C# I would write the following loop while ((line = Console.ReadLine()) != null) {.
I wanted to do ...
6
votes
1answer
85 views
Monoalphatic and Polialphabetic cipher in Ruby
This code encrypts a text with mono-alphabetic and poli-alphabetic substitutions ciphers.
For further info see:
Mono-alphabetic/Caesar Cipher
Poli-alphabetic cipher
...
7
votes
1answer
59 views
Using delegates to avoid duplicate creation of resources
I'm writing a PCL that uses an HttpClient to go visit a few sites and extract data from them. My initial code looked like this:
...
-1
votes
1answer
66 views
Filtering/mapping strategies
This is real JavaScript/Lodash code used in a project I'm currently working on, but actually this particular question bothers me quite often regardless of the language. Say, I need to generate some ...