Comments (3)
Given type specific functions are not required for decoding I think the encode_
prefix would be redundant- the second example you give could be this:
import gleam/jsone.{JsonValue}
pub fn encode_person(name: String, age: Int) -> JsonValue {
jsone.object([
tuple("name", jsone.string(name)),
tuple("age", jsone.int(age))
])
|> jsone.encode
}
This is the most concise, has unambiguous module names without renaming, and requires only a single module import.
from gleam_jsone.
I'm persuaded—I like that better. Reopening to track as a task.
from gleam_jsone.
Thank you for the feedback, @lpil!
I hear you, and had also wondered the same thing. I agree that the usage in your example feels a bit awkward.
The main reason I chose this module naming structure was that I thought the encoding functions would feel better to use this way. The usage I envisioned was like so:
import gleam/jsone/encode.{encode_json, JsonValue}
pub fn encode_person(name: String, age: Int) -> JsonValue {
encode.object([
tuple("name", encode.string(name)),
tuple("age", encode.int(age))
])
|> encode_json
}
So I guess that would be in contrast to something like this:
import gleam/jsone.{JsonValue}
pub fn encode_person(name: String, age: Int) -> JsonValue {
jsone.encode_object([
tuple("name", jsone.encode_string(name)),
tuple("age", jsone.encode_int(age))
])
|> jsone.encode
}
I still think I might like the former a little better... if you wanted to make it really clear what kind of data you were encoding, you could always alias the import, e.g.
import gleam/jsone/encode.{encode_json, JsonValue} as jsone_encode
pub fn encode_person(name: String, age: Int) -> JsonValue {
jsone_encode.object([
tuple("name", jsone_encode.string(name)),
tuple("age", jsone_encode.int(age))
])
|> encode_json
}
But I'll keep thinking about it!
Thank you again for the input! :)
from gleam_jsone.
Related Issues (6)
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 gleam_jsone.