Skip to main content

Questions tagged [functional-programming]

Functional programming is a programming paradigm based upon building abstractions using functions, isolating side effects and mutable state. Executing pure functions is thread-safe.

functional-programming
0 votes
0 answers
19 views

how to apply open-close principle on hierarchical typescript data types

let's imagine the following types autogenerated: I cannot change them. type BaseProblem = { name?: string; description?: string; } type SimProblem = BaseProblem & { type: "sim&...
Bertuz's user avatar
  • 2,518
2 votes
1 answer
53 views

What's the difference between placing a parser in its "box" vs using it without it? [duplicate]

So this is my parser, and two functions to run a parser: data Parser a = MkParser (String -> Maybe (String, a)) unParser :: Parser a -> String -> Maybe (String, a) unParser (MkParser a) inp =...
user20102550's user avatar
0 votes
3 answers
58 views

difficulty to understand the code, and maybe the concept itself (recursion problem)

this code below is from Grokking Algorithms book that is an exercise for the functional programming/recursion and an application for the D&C concept. the function finds the maximum number in a ...
Ahmed Salah's user avatar
0 votes
0 answers
18 views

Are Jsonnet variables the same as functions with no parameters?

Are Jsonnet variables, the ones that end with a semicolon (as opposed to the ones that end with a comma), the same as functions with no parameters? In the following Jsonnet program { c: local a = ...
Evan Aad's user avatar
  • 5,967
1 vote
1 answer
26 views

Referential transparency of Jsonnet functions

The Jsonnet Language Reference has this to say about Jsonnet functions: Functions in Jsonnet are referentially transparent, meaning that any function call can be replaced with its definition, without ...
Evan Aad's user avatar
  • 5,967
-1 votes
0 answers
17 views

What design should I use for this requirement: Static vs Non Static: Functional or OOP [closed]

Which design would you recommend for the following requirements: Static Methods, or traditional classes (immutable or something like a builder pattern). Are there any alternative designs or ...
Alessandro Rizzi's user avatar
0 votes
2 answers
53 views

How to use answers of parsers when nesting parsers (sequentially)

This is my Parser data Parser a = MkParser (String -> Maybe (String, a)) This is a parser that parses if a particular predicate holds true. satisfy :: (Char -> Bool) -> Parser Char -- takes a ...
user20102550's user avatar
-2 votes
1 answer
66 views

How do you write functional code that is not point-free (tacit)?

Edit Based on comments and close-vote flags, I'm seeing that I didn't clearly articulate what I'm trying to ask. So let me state it as succinctly and as straight-forwards as possible. What does it ...
Scotty Jamison's user avatar
2 votes
0 answers
64 views

Base class not recoginsed while using wild card generic

Why is the below not working? A b1 = new B(); Function<? super B, ? extends A> function = x -> new B(); A apply = function.apply(b1); It gives an error "Required type capture of ? ...
Sijo Kurien's user avatar
15 votes
7 answers
1k views

How can I write a std::apply on a std::expected?

In C++23, given: expected<A, string> getA(const X& x); expected<B, string> getB(const Y& y); C compute_all(const A& a, const B& b); Is there a way to avoid a classic ...
Teolazza's user avatar
  • 523
1 vote
1 answer
67 views

Understanding bracket use in Haskell - Parser that depends on previous parser gives error when using brackets

Ok so I'm trying to learn Haskell. This is my Parser. import Data.Char data Parser a = MkParser (String -> Maybe (String, a)) This is a parser which parses a string once, and depending on what it ...
user20102550's user avatar
0 votes
1 answer
36 views

How to Create a Generic Transformer Function for Subtypes in TypeScript (without type assertions)?

I am working on a personal project to learn functional programming with TypeScript and am experimenting with the pipe function and higher-order functions to create transformers in an expressive way. I ...
Nick Manning's user avatar
  • 2,923
1 vote
1 answer
77 views

How to use input string in a parser

I'm new to Haskell. This is my parser: data Parser a = MkParser (String -> Maybe a) This parses any string, gives the first character: -- anyChar anyChar :: Parser Char anyChar = MkParser sf ...
user20102550's user avatar
0 votes
0 answers
54 views

How to put setter function as a parameter?

I need to rewrite the test so that the setter function is passed as a parameter. That is, inside the test, I create a valid book, take an invalid value from the parameter, take the function, and this ...
yekashtalian's user avatar
0 votes
0 answers
14 views

Why does this recursive Function in Bend Hangs with list size > 11?

I was experimenting with the language called Bend. It claims to be "A high-level, massively parallel programming language". I was thinking of using it to validate a list of strings( 10 ...
Lord_help_me's user avatar

15 30 50 per page
1
2 3 4 5
1276