-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(array): add support to pipe into array.from #5165
Conversation
@@ -45,7 +45,7 @@ package array | |||
// | |||
// ## Metadata | |||
// tags: inputs | |||
builtin from : (rows: [A]) => stream[A] where A: Record | |||
builtin from : (<-rows: [A]) => stream[A] where A: Record |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm the biggest fan of this. I can't really think of another example where we do this kind of thing. I saw the PR and thought I'd like it, but the test cases are a bit hard for me to read.
Is there a specific request asking for this or is this just a quality of life change? I'd like to get some opinions from others on the team if they feel it looks right before clicking approve. If others like it, I've got no problem with hitting approve from a functional standpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsternberg This is coming from me as I prepare content for the rollout of dynamic types. It just removes the need to assign an array to a variable to render it as a table when parsing JSON using the dynamic package:
import "array"
import "experimental/dynamic"
jsonData = bytes(v: "
{
\"items\": [
{\"name\": \"a\", \"pos\": {\"x\": 10, \"y\": 10, \"z\": 20}},
{\"name\": \"b\", \"pos\": {\"x\": 30, \"y\": 99}},
{\"name\": \"c\", \"pos\": {}},
{\"name\": \"d\"}
]
}
")
parsed = dynamic.parseJSON(data: jsonData)
parsed.items
|> dynamic.asArray()
|> array.map(
fn: (x) => (
{
name: string(v: x.name),
posX: int(v: x.pos.x),
posY: int(v: x.pos.y)
}
)
)
|> array.from()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure. I'll just say I discourage people from using it this way outside of this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes with the json
use case its a bit awkward when every other function has a pipeforward argument.
For example:
dynamic.parseJSON(...)
|> dynamic.asArray()
|> array.filter(fn: (x) => x.bar == 42)
|> array.map(fn: (x) => ({foo: x.foo}))
|> array.from()
|> to()
Without this change users must do:
rows = dynamic.parseJSON(...)
|> dynamic.asArray()
|> array.filter(fn: (x) => x.bar == 42)
|> array.map(fn: (x) => ({foo: x.foo}))
array.from(rows: rows)
|> to()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What @sanderson said. My github hadn't refreshed with the above comments before writing my reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one additional update. Need to add this to the parameter description:
Default is the piped-forward array (`<-`).
2904eb8
to
ef14a83
Compare
With this change you can now pipe the `rows` argument into the array.from function.
ef14a83
to
f0b757f
Compare
With this change you can now pipe the
rows
argument into thearray.from function.
Checklist
Dear Author 👋, the following checks should be completed (or explicitly dismissed) before merging.
experimental/
docs/Spec.md
has been updatedDear Reviewer(s) 👋, you are responsible (among others) for ensuring the completeness and quality of the above before approval.