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.

100 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
294 views

nom Parser in Rust

I'm attempting to make a parser using nom in Rust. Nom implements parser combinators, so more complex parsers are built from simpler parsers. Because of this, I've started with a simple ID token ...
2
votes
0answers
77 views

React - Higher Order Component

My first go at a Higher Order Component in react. Aims to give a component the ability to call an url repeatedly with a given refresh interval. Seems to be working as I want. I'm not 100% confident ...
2
votes
0answers
157 views

Groovy Map/Reduce for Jenkins DSL

Jenkins DSL doesn't support collect and inject from what I can tell (I get missing method exceptions when I try), so I ...
2
votes
0answers
29 views

Test Driven Development in JS and Sinon Stub

I am going through some TDD and BDD tutorials which guide one through implementing a simple beverage-ordering system. While I think I understand the material, I am still wondering about some ...
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
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 _....
2
votes
0answers
102 views

Computing nth roots of a number - SICP exercise 1.45

From SICP Exercise 1.45: We saw in 1.3.3 that attempting to compute square roots by naively finding a fixed point of x/y does not converge, and that this can be fixed by average damping. ...
2
votes
0answers
852 views

D3.js multi-line graph

Here is my JS code which uses the D3.js library (mostly snipped from other examples). I want to graph the acceleration of a point in 3D-space which changes with respect to time. The X-axis of the ...
2
votes
0answers
91 views

Extracting data for a tag cloud using Lazy.js

I've just started using Lazy.js, which is my first exposure to a "functional style" javascript library. I'm still utterly lost as to which of the hundred different functional javascript libraries to ...
2
votes
0answers
46 views

Functional, Loaner-Like Pattern For Consuming SQS Queues, Deleting Queue Items On Success

My program fetches input from a RabbitMQ or Amazaon SQS-like queue. There is not always input available in the queue. If a message is available, it triggers work. If that work is successful, ...
2
votes
0answers
193 views

Using my own Optional type with fold method in groovy

I have written an Optional type in groovy roughly based on java8s Optional. I implemented and use a fold method and would like to know if it can be improved. First, ...
1
vote
0answers
23 views

Toggling the background color of a page using JavaScript closures

This question is to see if I can get some input on the "design pattern" I tried to implement here. I'm just learning about closure in JavaScript and I think I'm starting to get it. I'm wondering if ...
1
vote
0answers
38 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
1
vote
0answers
15 views

Combinable filters for Python Pandas dataframe structure

This is an extension of my other question here. I have applied suggestions from 200_success in real-life problem at hand that deals with modelling extensible and ...
1
vote
0answers
37 views

Transform vcards into contacts using functional programming in JavaScript

Context: I'm building a React app using Ramda as a helper library for functional programming. Users can import contacts into the app. These contacts can be vCards. I've written a function that: ...
1
vote
0answers
57 views

Rotate a list by k elements

The task: Write a function that rotates a list by k elements. For example, [1, 2, 3, 4, 5, 6] rotated by two becomes [3, 4, 5, 6, 1, 2]. Try solving this without creating a copy of the list. ...
1
vote
0answers
88 views

Sort a list using a reverse helper function

The task: Given a list, sort it using this method: reverse(lst, i, j), which reverses lst from ...
1
vote
0answers
51 views

Find the square root of n

The task: Given a real number n, find the square root of n. For example, given n = 9, return 3. My solution: ...
1
vote
0answers
49 views

KMP algorithm in scala

I implemented KMP pattern matching algorithm in Scala. My code works but it looks more imperative and a scala translation of C/C++ implementation. I am not able to figure out how to manage multiple ...
1
vote
0answers
109 views

Max heap in Haskell

I wrote a (max) heap in Haskell which is balanced after every (public) operation. Not based on any documentation. Focus is on: speed, that is the right time-complexities (not necessarily optimal); ...
1
vote
0answers
46 views

Closest 3Sum in Scala

This question is taken from Leet code. Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three ...
1
vote
1answer
115 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
1
vote
0answers
88 views

Immutable Queue with Bulk-Enqueue

I recently needed a data structure with FIFO queue semantics that supported efficient bulk-insertion (often need to enqueue thousands of messages at once). I took a look at Purely Functional Data ...
1
vote
0answers
141 views

F# Operation Framework (Railway-Oriented Programming + Task/Async/Lazy)

I recently published the initial version of what is effectively my first open-source software package, a Railway-Oriented Programming Framework for F# that encapsulates Tasks, Async Workflows, and ...
1
vote
0answers
163 views

WebSocket based API library in Julia

I made a very bare-bones API "library" in Julia which should abstract the interaction with the API. The API is fairly complex - it's based around 2 core layers an HTTPS/REST API for general ...
1
vote
0answers
45 views

Creating and manipulating a map for a text based game F#

I have put my whole code so far below, but what I am most interested in is how best to implement the map and utilise it. Any tips on organising my code and keeping it clean would also be greatly ...
1
vote
0answers
47 views

Code which buffers objects and schedules saving them from buffers, after applied some actions to it

Originally i have a function like this: ...
1
vote
0answers
51 views

Custom indexeddb modules while trying to maintain the functional paradigm as much as possible

I'm a Web Development student, and I just started learning indexeddb a little while ago. At present my teacher hasn't taught us Promises, and I'm not really sure he plans to. So, I took the initiative ...
1
vote
0answers
92 views

Folktale 2 skeleton workflow for resetting a forgotten password

I am learning more about functional programming via loop recur's online book Mostly Adequate Guide to Functional Programming, and Brian Londorf's video series on egg head. I started using ...
1
vote
0answers
305 views

Fetching weather data from API

I was experimenting with some code to fetch the current weather data as well as getting the hourly forecast. I could have done ...
1
vote
0answers
22 views

Retrieve compilation files of smart contracts asynchronously via Ajax and add to database

I need to retrieve two files that are labeled :abi and :bin from a server. I then want to add these files to a database in a ...
1
vote
1answer
295 views

Grouping models without dictionary

I want to group an array of structs only using arrays into an array of new structs. In this example I want to group the Person structs by ...
1
vote
0answers
87 views

Purely functional minecraft-like mesh compiler

I'm creating a minecraft clone (for practice), in scala, using largely functional programming. When a chunk doesn't have a mesh loaded into VRAM, it create a Future for the vertex and index arrays, ...
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 ...
1
vote
0answers
51 views

Implementation of catch test framework in Racket

As an exercise in learning how to use Racket macros I decided to implement a subset of the features in the catch test framework for C++. In particular the catch test framework has a unique feature ...
1
vote
0answers
81 views

String and Date manipulation exercise using functional programming style

I was reading a question on stackoverflow recently and I became a little curious/interested in the philosophy behind Ramda (functional programming for Javascript). So I thought I would try an exercise....
1
vote
0answers
89 views

Tool for composing functors

What do you think of this code? ...
1
vote
0answers
199 views

Merging trees in scalaz

I just built a function to merge a set of List[A]s into a single scalaz.Tree[A]. Specifically, if I have the following three <...
1
vote
0answers
93 views

Using interface for generated functions or just create plain functions

I was wondering which code might be better. I'm abstracting away the rote code as follows: ...
1
vote
0answers
184 views

Remove items, resize columns, shuffle a list

I'm at the very beginning of starting to learn object-oriented programming patterns in JavaScript and PHP. Up until now I've always coded in a purely functional pattern. I'm doing a lot of reading, ...
1
vote
0answers
2k views

Idiomatic Scala for nested map/flatmap

Does anybody have an idea on how to make this code more idiomatic? I tried to use scalaz Traverse, but it didn't really help. Given the types and method signatures: ...
1
vote
0answers
328 views

Integer implementation in Idris

This is a try at implementing integers in Idris. Any advice or comments are most welcome. ...
1
vote
1answer
58 views

Create a collection of functions tupled with a collection of parameters, and execute the collection in order in Scala

I am trying to create a collection of Unit functions that have any arity and type, and will execute them in order. This is the working implementation that I have: ...
0
votes
0answers
21 views

Create a template literal tag to remove whitespace from a string

I'm just getting into functional programming (as in, just started reading the book) and as practice I'm trying to refactor a past answer I wrote to fit in line with the functional style. The ...
0
votes
0answers
38 views

Given time intervals determine if a person could attend all meetings

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
0
votes
0answers
67 views

Rewrite a Haskell function to be total

I've written this function to give the neighbours of a vertex in a graph: ...
0
votes
0answers
16 views

QTP/UFT Prints the time in takes to complete every task in a Log using VBScript

This script is meant to log the time it takes to complete functions in order to find the locations where performance could be improved in QTP. If a duplicate log is attempted, the script changes the ...
0
votes
2answers
60 views

Count Substrings for a binary string

Problem is taken from leet code. Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings ...
0
votes
0answers
53 views

Advent of Code 2017 Day 5 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 2nd part of Day 5): https://adventofcode.com/2017/...
0
votes
1answer
60 views

Is it possible to DRY these 2 methods of a tailrec Node Tree?

I have a Tree structure composed by Node class. I have to @tailrec method that are visiting up to the root. Those 2 methods ...