Category "functional-programming"

Creating an immutable object as a class in javascript

I would like to create an object that has various methods, but the core data can never be changed. If using a class-based approach, are using private variables

In groovy, how can i iterate over a csv file and call a function for every "group" that as a different value on some of the columns?

In Groovy and running on a jenkins pipeline, I am using the readFile function from jenkins to read the csv file. Example csv: name val1 val2 John 2 122 John 2

Dealing With Assertions in Functional Code

While doing functional programming I often end up in situations where I know something that the type system of the language does not know. Consider the followin

HOC with functional component

I'm trying to make a simple HOC (Higher Order Function) with a functional component IN React.js. I have done the following, and it's compile, but nothing is sho

Improve debugging output of a recursive function

I have the following recursive function to count the number of ways change can be returned given various coin denominations: function makeChange(amount, coi

Improve debugging output of a recursive function

I have the following recursive function to count the number of ways change can be returned given various coin denominations: function makeChange(amount, coi

How to access a function defined as key of an object from within another function defined as key of same object in JS

Given below code, I need to reuse functionality from innerFunc1 and innerFunc2 in innerfunc3, but I am not sure, how innerFunc1 and innerFunc2 can be accessed i

Is there a more functional way to merge and foreach/sort two arrays in TypeScript, React?

I'm learning React and TypeScript. For sake of practise, I've tried to create a calculator design by merging two arrays to map a single array onto the grid (dis

Type inference in ZIO giving Any in for comprehension

So I have written a method to count the number of lines in a file in ZIO. def lines(file: String): Task[Long] = { def countLines(reader: BufferedReader): Ta

Count and print unique list items in one chain using Java Streams

I'm trying to achieve this using only functional programming constructs (Streams, Collectors, lambda expressions). Let's say list is a String[]: {"Apple", "Sa

Python - applying tupple to a function in functional toolz.pipe

I want to use a function which accepts some arguments in a toolz.pipe, but data input is a tuple. I know how to solve it, but I think there must be some solutio

Python fuctional style iterative algoritm?

In Haskell there is a simple list function available iterate :: (a -> a) -> a -> [a] iterate f x = x : iterate f (f x) In python it could be implemen

How to pre-fill arguments to a function in Ruby?

Let's say I have a function foo: def foo(A, B, C) A + B + C end And I call it like this, with only the last parameter changing: foo("foo", "bar", "123") foo("

How would a functional language actually define/translate primitives to hardware?

Let's say I have a few primitives defined, here using javascript: const TRUE = x => y => x; const FALSE = x => y => y; const ZERO = f => a =>

Why use Arrow's Options instead of Kotlin nullable

I was having a look at the Arrow library found here. Why would ever want to use an Option type instead of Kotlin's built in nullables?

How can memoize be implemented in pure functional languages?

One advantage of pure functions is that their inputs fully determine their outputs, allowing the result to be cached for later use. However, I don't see how thi

How can I write test cases for instances in Haskell

I have an instance of Num for a type I created called Vec: instance Num Vec where (+) (Vec x) (Vec y) = Vec (zipWith (+) x y) And I am trying to write a test

Project Euler #1 in JavaScript on HackerRank

I'm having some trouble with the test cases for Project Euler #1 on HackerRank and was hoping someone with some JS experience on HackerRank could help out. B

Is there a more Functional way to aggregate a collection into set of Mongo Filters conjugated by OR?

We have a microservice which enables consumers (indirectly) to query a database, where we have our own logic to limit what consumers can do with the queries. Wh

Swift: What's the best way to pair up elements of an Array

I came across a problem that required iterating over an array in pairs. What's the best way to do this? Or, as an alternative, what's the best way of transformi