All Questions
Tagged with functional-programming design-patterns
36 questions
2
votes
1
answer
288
views
Did the term "decorator" originate with OOP design patterns?
The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have ...
1
vote
1
answer
754
views
How could I apply the strategy pattern to a react component? [closed]
For the following component, how would I extract the unit logic to allow for composition? In my actual app I am trying to reduce the amount of logic encoded in the component and I have decided that ...
1
vote
1
answer
236
views
Are there any drawbacks to partial application?
Consider the following Typescript code:
function exampleAction(target: Target, options: ExampleActionOptions) {
// ...
}
export function getExampleAction(options: ExampleActionOptions) {
return (...
4
votes
2
answers
1k
views
How to organize a chain of functions that share parameters, functional programming
When trying to follow a functional programming paradigm, I often find myself in a situation where I have a chain of functions that I would want to combine/compose somehow, but they all also take in a ...
6
votes
1
answer
473
views
Terse finite state machines in Haskell
I'm writing a parser for a markup language in haskell, and a finite state machine fell out of my ideal API. I have code that looks a bit like this:
Token = BoldWord String | Word String | ...
1
vote
2
answers
249
views
Connecting classes by passing method references
I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass ...
4
votes
3
answers
963
views
Is this extensive usage of closure a known (anti-)pattern? And does it have a name?
I often use function closures for storing data (e.g. database URL), which doesn't change between function calls. Is this an (anti-)pattern? Does it have a name?
While developing apps, which recieve ...
-1
votes
1
answer
210
views
Refactoring: Pythonic way of reducing the subclasses?
background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
1
vote
4
answers
883
views
Design pattern for a function class
I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions:
https://stackoverflow....
1
vote
1
answer
355
views
Is designing a generic parameterized class with methods of it accepting higher order functions a functional technique that we can use in Java 8?
Recently I have asked this question: How do you rewrite the code which using generics and functionals in Java 8 and mixing oop and functional programming by using only object-oriented? on ...
1
vote
1
answer
448
views
What do you call the state reducer pattern used by redux?
Redux uses a state reducer pattern where essentially you create a pure function that looks like:
function reducer (previousState, action) {
//...
return newState;
}
This looks similar to ...
1
vote
1
answer
171
views
Structuring a pipe for function composition when an intermediate result is needed by later functions
I have a set of pure functions that can be composed almost trivially in a pipe as
initialValue -> [f] -> [g] -> [h] -> ... -> [m] -> [n] -> [o] -> outputValue
The problem I ...
12
votes
6
answers
2k
views
Best Practice - Wrapping if around function call vs Adding early exit if guard in function
I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax.
I'm not asking what is the best approach when in a function, I am ...
2
votes
3
answers
472
views
Swappable state object or decoupling data and functions
I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
1
vote
5
answers
2k
views
Software design pattern for class method that only should be called once
Say I have a TypeScript class:
export class TypeCreator {
entities: Set<Whatever>
registerEntities(e: Set<Whatever>): Set<Whatever>{
return this.entities = e;
}
}
if ...