I finished working on an initial version of a pattern matching library and wanted to share it with you guys. Please share your thoughts if you have the time and are interested. Yes this is a bit of a shameless plug, but I don't know of other communities where I can share this.
Hi, I'm trying to make this peace of code more functional like, and more elegant, so this:
checkActive(service).then(
isActive => isActive
? stopService(service)
: startService(service)
)
Became this:
checkActive(service).then(
ifElse(
identity,
partial(stopService, [service]),
partial(startService, [service])
)
)
But to me, the first one seems easier to understand. Maybe there's a better approach? Would love any insights on this... thanks!
I think I found a bug in includes
:
const fn = includes(__) (['foo', 'bar'])
const fn2 = includes(__, ['foo', 'bar'])
console.log(
fn('foo'), // false
fn('bar'), // false
fn2('foo'), // true
fn2('bar'), // true
fn2('not present'), // false
)
Does ramda have a point-free way to do this:
const callMethod = obj => obj.someMethod;
I could do:
const callMethod = R.compose(R.call, R.prop('someMethod'))
But that does not seem any clearer and certainly less concise. I was thinking perhaps ramda has a builtin fn for it, but I couldn't find it...
Ideally, generically, e.g.:
const callMethod = curry((name, obj) => obj[name]())
nth
: R.pipe(
R.toPairs,
R.filter(R.pipe(
R.nth(1) as (value: [string,string]) => string,
R.both(R.pipe(R.isNil, R.not), R.pipe(R.startsWith('workspace:'), R.not))
) as (v: [string,string]) => boolean),
R.fromPairs
) as (data: Record<string,string>) =>Record<string,string>
Hi, I am having this problem with TS type. Do you have any idea?
error
No overload matches this call.
The last overload gave the following error.
Argument of type 'concat_list_10<File>' is not assignable to parameter of type 'Morphism<unknown, unknown>'.
Types of parameters 'b' and 'value' are incompatible.
Type 'unknown' is not assignable to type 'unknown[]'.ts(2769)
over.d.ts(106, 5): The last overload is declared here.
The code
const updateFiles = R.concat(files)
set(state => {
return R.over(lensFiles, updateFiles, state)
})
export interface File {
id: string;
link: string
}
interface
```export interface UserData {
_id: string | undefined;
files: File[];
}
state example
const state = {
user: { data: {
id: 1,
files : [{id:"1", link: "somelink"}]
}}
}
Version
"ramda": "^0.27.1",
"@types/ramda": "types/npm-ramda#dist",
const filterFns = pipe(
reject(pipe(values, head, isNilOrEmpty)),
... // some other code, not important for now
])),
)([...$or, ...$and]);
pathTo
and isNilOrEmpty
are helpers in our code based on Ramda...
R.contains
with R.includes
at https://ramdajs.com/docs/#onError: './src/curry' is not defined
at RunKit
I am having an issue understanding next lens code:
import {compose, lensProp, view} from "ramda";
const truth = compose(
lensProp('foo'),
lensProp('bar'),
lensProp(1),
)
const obj = {
foo: {
bar: [false, true]
}
};
console.log(view(truth, obj)) // true
I could understand if we used pipe instead of compose, but compose performs right-to-left function execution and that confuses me.
const fetchPlanets = async (url) => await fetch(url);
const checkResponse = (response) => response.ok ? response : 'error';
const getJson = async (response) => await response.json();
const logger = data => console.log(data);
const gettingData = pipe(
fetchPlanets,
checkResponse,
getJson,
logger
)
gettingData('https://swapi.dev/api/planets');
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