Hi guys!!!
Is it sensible to suggest this way of constructing types? (example below)
import gleam/option.{None, Some}
import grom/channel
import grom/client
const token = "l.u.c.y"
const guild_id = "768594524158427167"
pub fn main() {
let client = client.Client(token:)
let data =
channel.CreateText(
..channel.new_create_text(named: "hello", in: guild_id),
position: Some(100),
)
|> channel.CreateTextChannel
client
|> channel.create(using: data, because: None)
|> echo
}
Essentially, I'm providing a function called new_create_text, which creates a new CreateText value, which is filled with a lot of option.Nones:
pub fn new_create_text(named name: String, in guild_id: String) -> CreateText {
CreateText(guild_id, name, None, None, None, None, None, False, None, None)
}
This saves the user from typing all of these Nones.
Then I pipe it into a channel.CreateTextChannel constructor, which is of the channel.Create type:
pub type Create {
CreateTextChannel(CreateText)
CreateDmChannel(CreateDm)
CreateVoiceChannel(CreateVoice)
CreateCategoryChannel(CreateCategory)
CreateAnnouncementChannel(CreateAnnouncement)
CreateStageChannel(CreateStage)
CreateForumChannel(CreateForum)
CreateMediaChannel(CreateMedia)
}
This is because, well, I need to accept one type into the function (or make a lot of very similar-looking functions).
Would you improve on anything in this code?
If you'd like more context, either ask or see for yourself at https://tangled.sh/@folospior.me/grom
||src/channel.gleam for the library code||
||examples/src/examples.gleam for the example code||
A Discord API Library for Gleam! 💫