Comments (12)
ah ty @jlissner ! That explains why adding tap
first fixes things as pipe uses the first function to determine the arity of the function it creates
from ramda.
So I think the problem is the bare JSON.parse
? I'm not sure why tap
seems to fix this! The simplest solution is probably just adding an arrow function
R.pipe(
R.tryCatch(x => JSON.parse(x), R.always({})),
R.pathOr("", ["choices", 0, "delta"]),
R.objOf("delta"),
R.mergeRight({ isDone: false })
)
We created R.bind
for situations like this, but it doesn't actually seem to solve it here.. not sure exactly what is going on, maybe someone else can shed some more light
from ramda.
JSON.parse accepts 3 arguments, so ramda is auto-currying the remaining arguments, you can do R.unary(JSON.parse)
to fix the issue:
R.pipe(
R.tryCatch(R.unary(JSON.parse), R.always({})),
R.pathOr("", ["choices", 0, "delta"]),
R.objOf("delta"),
R.mergeRight({ isDone: false })
)
from ramda.
Yep, I mean it's not the issue with Ramda, just was asking on how to make this github issue more indexable for other people if faced with an alike situation.
from ramda.
Hi @orsenkucher , could you post some sample input?
from ramda.
@kedashoe Hi!
Yes, sure!
I use this functions with deltas(data.toString())
.
Here are few samples of console.log(JSON.stringify(data.toString()))
const data = /* Just paste string from sample */;
const res = deltas(data);
console.log(res);
"data: {\"id\":\"chatcmpl-7TFKQZlJPXyd33RDvEQKAV1QZKzE8\",\"object\":\"chat.completion.chunk\",\"created\":1687204790,\"model\":\"gpt-3.5-turbo-0613\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-7TFKQZlJPXyd33RDvEQKAV1QZKzE8\",\"object\":\"chat.completion.chunk\",\"created\":1687204790,\"model\":\"gpt-3.5-turbo-0613\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"Hello\"},\"finish_reason\":null}]}\n\n"
"data: {\"id\":\"chatcmpl-7TFKQZlJPXyd33RDvEQKAV1QZKzE8\",\"object\":\"chat.completion.chunk\",\"created\":1687204790,\"model\":\"gpt-3.5-turbo-0613\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"!\"},\"finish_reason\":null}]}\n\n"
"data: {\"id\":\"chatcmpl-7TFKQZlJPXyd33RDvEQKAV1QZKzE8\",\"object\":\"chat.completion.chunk\",\"created\":1687204790,\"model\":\"gpt-3.5-turbo-0613\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\".js\"},\"finish_reason\":null}]}\n\n"
"data: {\"id\":\"chatcmpl-7TFKQZlJPXyd33RDvEQKAV1QZKzE8\",\"object\":\"chat.completion.chunk\",\"created\":1687204790,\"model\":\"gpt-3.5-turbo-0613\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" is\"},\"finish_reason\":null}]}\n\n"
from ramda.
Also if you call R.ifElse(..., ..., (x) => R.pipe(...)(x))
it will work.
from ramda.
@kedashoe Thanks for your input!
Yeah, JSON.parse seems just not to work with Ramda.
(x) => R.curry(JSON.parse)(x)
breaks it again.
I'm curious too, and it'd be nice if someone else could provide further insight.
R.tap(() => {})
doesn't actually do anything, but it likely changes the context in which R.tryCatch
calls JSON.parse
, making the error go away. So it's better to fall to another solution.
R.bind(JSON.parse, null)
isn't working as well, so using the x => JSON.parse(x)
workaround is probably the best bet for now. Even though it's less elegant, at least it behaves as expected
from ramda.
Thanks @jlissner!
Seems obvious now ahaha. Should I rename the issue to "Auto-currying in tryCatch with JSON.parse" or something?
from ramda.
I don't think it would be considered an issue. Ramda has made a choice to auto curry arguments in certain settings.
You could make a post stating your case for why ramda should not auto curry in a tryCatch if you feel strongly about it.
from ramda.
I don't think it would be considered an issue. Ramda has made a choice to auto curry arguments in certain settings.
Yes ramda does this pretty much everywhere to determine arity of the functions it creates, it would be quite a change to do something different at this point. It is usually the builtins/functions which accept optional arguments which catch people out. I will close now but feel free to discuss further.
from ramda.
Yep, I mean it's not the issue with Ramda, just was asking on how to make this github issue more indexable for other people if faced with an alike situation.
Ah good thought.. probably fine to leave it, but ya something like what you suggested is good
from ramda.
Related Issues (20)
- R.without broke backwards compatibility on #2603 HOT 1
- update vulnerable dependencies
- update sanctuary
- bug: code coverage failing
- enhancement: update prop to include deeply nested objects
- enhancement: update path to use prop
- Support promises for pipe and pipeWith HOT 2
- illegal invocation HOT 4
- `groupBy` throws inscrutable errors when inferred to be a transducer HOT 4
- Incorrectly implementation of the 'unless' function HOT 1
- TypeScript fails compilation on reduce currying HOT 1
- Add minify to partial build HOT 1
- 0.30.0 upgrade guide HOT 3
- Is there a problem with curryN? HOT 3
- Deno.land releases have stopped ~3 years ago HOT 7
- Since v0.30 functions curried by Ramda break when used with `R.__` from another Ramda version HOT 1
- Consider Major Version Update For Breaking Changes HOT 6
- 0.30.0 `propEq` is wrong
- 0.30.0 @types/ramda lensProp HOT 1
- 0.30.1 upgrade guide
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ramda.