Hi! I'm using Ramda in a project and editing with VSCode. I'm trying to document my code with JSDoc but VSCode's Intellisense automatically infers my function types (so doesn't show my JSDoc comments). Does anyone know how to force VSCode to stop inferring if there is JSDoc documentation?
/**
* @param { Array<Number> } arrayOfNumbers
* @return { Number } sum - the sum of the arrayOfNumbers
*/
const getSumOfArrayElements = reduce (add, 0)
Intellisense just shows what R.reduce
returns:
const getSumOfArrayElements: (list: readonly any[]) => number
Asking here because I figure other Ramda users may have run into this. Thanks!
I don’t know what I have to do facing the following error concerning type.
Could someone help me with this?
Code
import { concat, flip, pipe } from 'ramda'
const concatAfter = flip(concat)
const foo = [1, 2, 3]
const bar = [4, 5, 6]
type Exec = (x:number[]) => number []
const exec:Exec = pipe(
concatAfter(foo),
concatAfter(bar)
)
Error
[tsserver 2322] [E] Type '(s2: string) => string' is not assignable to type 'Exec'.
Types of parameters 's2' and 'x' are incompatible.
Type 'number[]' is not assignable to type 'string'.
Packages
ramda@0.28.0
@types/ramda@0.27.64
flip
, and write type explictly:const concatAfter = (list1: number[]) => (list2: number[]) =>
concat(list2, list1);
const foo = [1, 2, 3];
const bar = [4, 5, 6];
type Exec = (x: number[]) => number[];
const exec: Exec = pipe(concatAfter(foo), concatAfter(bar));
@types/ramda
and I made a code sandbox with some code here https://codesandbox.io/s/youthful-borg-rh1d4b?file=/src/index.tsNo overload matches this call.
. I'm not really sure what it's trying to tell me... has anyone encountered something similar before?
Can you explain me why ramda does not work with plain objects in typescript? ```const name1 = R.prop("name", { test1: 1, name: "Ivan" }); //works
const extractName = R.prop("name");
const name2 = extractName({ test1: 1, name: "Ivan" }); //typescript complains
const obj = { test1: 1, name: "Ivan" };
const name3 = extractName(obj); //works
```
Hey guys, given an array of numbers, I need to partition elements by difference to their preceding element. Example:
const difference = 10;
const elements = [0,5,10,15,20,30,35];
// desired result:
[[0,5,10,15,20], [30, 35]]
Is there something in the library that allows looking at the previous element's value when iterating?
What is a functional way to find a specific size object from this kind of nested data structure. For example, I want to iterate until I find a size { id: 6 }
and return it. Do I have to use 3 nested loops?
Input:
[
{
id: 'a',
colors: [
{
name: 'blue',
sizes: [
{ id: 1 },
{ id: 2 },
//...
]
},
{
name: 'green',
sizes: [
{ id: 3 },
{ id: 4 },
//...
]
},
//...
]
},
{
id: 'b',
colors: [
{
name: 'black',
sizes: [
{ id: 4 },
{ id: 6 },
//...
]
},
{
name: 'white',
sizes: [
{ id: 7 },
{ id: 8 },
//...
]
}
]
},
//...
]
I'm sure a number of you may have already heard but there is a new ECMAScript proposal for "Types as Comments". It's basically a way to allow TypeScript and Flow code to run in the browser as is. It's just Stage 0 and might get shelved before ever making it somewhere but the interesting thing is that it's being pushed by representatives from Microsoft and it already has some heavy hitters from the ECMAScript proposal community engaging with it. As we all know, using TS for functional programming has some frustrating limitations and hoops to jump through. So I just want to make sure the functional JS is community aware of the proposal and encourage people to go explore the proposal and speak up so we're represented in the discussion.
Thanks!
is there something like until
but returning array of all values instead of last one?
like in example
R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128
it would return [1,2,4,8,16,32,64,128]
ok I found unfold
const f = n => n > 100 ? false : [n, n * 2];
R.unfold(f, 1); // =>[1,2,4,8,16,32,64]
```
I had a look at https://github.com/ramda/ramda.github.io and was actually wondering, if there is some kind of build process involved, that just pushes to the repo, or if for new versions, someone just copies the folder and edits everything by hand. Would love to contribute to the docs, but wanted some understanding beforehand.
(hope this is the right channel for this)
export function omit<T extends object, K extends keyof T>(names: readonly K[], obj: T): Omit<T, K>;
T extends object
prevents to pass something else, bcs now it allows to pass anything. And K extends keyof T
allows to narrow types and gives us nice autocompletion.
Is there a way to handle HTTP errors that happen when using the declarative HTTP Client? For example, I have defined a client interface with this method:
Publisher<DetailsResponse> getDetails(@Header(AuthConstants.AUTH_TOKEN_HEADER) String authToken,
@Body DetailsRequest request);
Elsewhere in a controller, I use the client to resolve a request:
public Publisher<DetailsResponse> mappings(@Body DetailsRequest detailsRequest , Authentication authentication) {
//if (1 == 1) throw new HttpClientResponseException("Error", HttpResponse.badRequest());
String authToken = (String) authentication.getAttributes().getOrDefault("authToken", "");
return myClient.getDetails(authToken, detailsRequest );
}
If the client returns a 200, everything works fine. However, if the client encounters an exception, perhaps the server returned a 500, I would like to be able to handle the error myself and return a response of my choice.
I've defined an HttpClientResponseExceptionHandler, which works if the error occurs in my Controller code (see the commented out line that I used as a test), however, if the exception happens in the declarative client, my handler is never invoked. In that case, the error is thrown in the DefaultHttpClient code.
I'm sure if I used the low-level HttpClient I could handle this, but I was wondering if I'm missing some trick when using the declarative client? This is using the 3.4.2 version of Micronaut.
Thanks!
Hi, I am still kinda new to Ramda, and I am facing some trouble figuring out the right way to create the function.
Hope someone can help me here.
I have a list of list which is grouped by key = a
[
[{ a: 1, b1: 1}],
[{ a: 2, b2: 2}, { a: 2, b2: 3, c2: 2}],
[{ a: 3, b3: 3}, { a: 3, c3: 5}]
]
Each item in the outer list contains only one or two elements.
Now my goal is - if it contains 2 elements I want to do mergeRight
, and if it's just one element I want to keep it as it is.
I was thinking I can map over the outer list and do R.mergeRight(R.nth(0), R.defaultTo({}, R.nth(1))). So basically R.map(R.mergeRight(R.nth(0), R.defaultTo({}, R.nth(1))))(list)
.
However, I am not able to make it work. My guess is the item is not being passed to R.nth function.
Can anyone help me figure out the problem?
const list = [
[{ a: 1, b1: 1}],
[{ a: 2, b2: 2}, { a: 2, b2: 3, c2: 2}],
[{ a: 3, b3: 3}, { a: 3, c3: 5}]
]
const mergeRightIfNeeded = R.map(
R.when(
R.propEq('length', 2),
R.apply(R.mergeRight)
)
)
const result = mergeRightIfNeeded(list)
console.log(result);
Hi! Does ramda have a function, which can be used as the marked code snippet?
It should iterate over an array, call a(n async) function, and if it succeeds, it should aggregate the results as long as no one rejects.
takewhile seems useful, but I cannot put the pieces together.
I have this function:
const extractEntities = (name: string) => ifElse(propEq(`${name}s`, {}), always([]), pathOr([], [`${name}s`, name]))
But as you see I am using arrow function, and as I had read in some articles about ramda usually when you write arrow function you can substitute by ramda function.
So is there any way to improve the function above??