Comments (2)
Thanks for the issue.
I think that the compiler should not have allowed fn (item json2.Any) !string
to be used as an argument of .map(), since a result value has to be handled right away, not stored in an array.
It should have been a checker error, instead of a cgen one.
A fixed version of the code above may look like this:
import x.json2
fn main() {
json_str := '{"data": [{"name":"bob"}, {"name":"tom"}]}'
decoded := json2.raw_decode(json_str) or {
eprintln('Failed to decode JSON: $err')
return
}
data_arr := decoded.as_map()['data']!.arr()
names := data_arr.map(fn (item json2.Any) string {
return item.as_map()['name'] or {''}.str()
})
println(names)
}
from v.
i think it should require !
on map()
result if callback returns Result
's, otherwise everyone will make their maybe_map
/``maybe_map_map` functions
from v.
Related Issues (20)
- Mutating immutable variable HOT 9
- Coercing a pointer into an option uses the address as if it were a value
- c error on unwrap of an option type in a match HOT 2
- "bad" error message for unterminated `println`
- Compiler failed while returning array for const init
- C Error while returning struct ref for interface directly from other method call
- undefined values for an option multireturning function, that executes `return none`, instead of a checker error HOT 1
- Tools not built in subfolders with build-tools
- Sumtypes used as C union types not working HOT 2
- cannot return an option from function that returns alias to `Option` as `Result` HOT 2
- Cannot run v.exe due to a compiler error HOT 1
- Type-casting issue when providing a generic function as argument. HOT 2
- x.json2 can not decode properly a struct with a fixed array field HOT 1
- [json] decoding struct with i32 member results in `cgen error: json: i32 is not struct`
- a closure called instantly with an `or` block fails to compile
- [x.json2] Decoding array type panics HOT 1
- have a better to way to detect arrays from compile time HOT 2
- unchecked error handling for empty or blocks used in string interpolation `x := "${ f() or {} }"` HOT 3
- Custom iterator struct constructor does not work with `for x in Iterator{} {`
- useless time module warning in a bad module definition error HOT 3
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 v.