gleamgen/module
Types
pub opaque type ExternalModule
pub type ModuleDefinition {
Definition(details: definition.Definition, value: Definable)
}
Constructors
-
Definition(details: definition.Definition, value: Definable)
pub type ReplacementConfig {
ReplacementInline
ReplacementUpdateDefinition(
fn(definition.Definition) -> definition.Definition,
)
}
Constructors
-
ReplacementInline -
ReplacementUpdateDefinition( fn(definition.Definition) -> definition.Definition, )
Values
pub fn from_source_map(
module: source.SourceMapped(glance.Module),
) -> Module
pub fn render(
module: Module,
context: render.Context,
) -> render.Rendered
pub fn render_imported_module(
module: import_.ImportedModule,
) -> render.Rendered
pub fn replace_function(
function_name: String,
module: Module,
func: fn(option.Option(source.SourceMapped(glance.Function))) -> function.Function(
func_type,
ret,
),
config: ReplacementConfig,
handler: fn(Module, expression.Expression(func_type)) -> Module,
) -> Module
pub fn with_constant(
details: definition.Definition,
value: expression.Expression(t),
handler: fn(expression.Expression(t)) -> Module,
) -> Module
pub fn with_custom_type1(
details: definition.Definition,
type_: custom.CustomTypeBuilder(repr, #(#(), a), generics),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
) -> Module,
) -> Module
Define a custom type with one variant.
let cat =
custom.new()
|> custom.with_variant(fn(_) {
variant.new("Cat")
|> variant.with_argument(option.Some("name"), type_.string)
|> variant.with_argument(option.Some("age"), type_.int)
|> variant.with_argument(option.Some("has_catnip"), type_.bool)
})
use cat_type, cat_constructor <- module.with_custom_type1(
definition.new("Cat"),
cat,
)
The type can be instantiated with custom.to_type.
The constructors can be used to create values of the type (constructor.to_expression)
or pattern match on values of the type (pattern.from_constructor).
To define a custom type with a dynamic number of variants, see with_custom_type_dynamic.
pub fn with_custom_type2(
details: definition.Definition,
type_: custom.CustomTypeBuilder(repr, #(#(#(), a), b), generics),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
) -> Module,
) -> Module
Define a custom type with two variants.
let animals =
custom.new()
|> custom.with_variant(fn(_) {
variant.new("Dog")
|> variant.with_argument(option.Some("bones"), type_.int)
})
|> custom.with_variant(fn(_) {
variant.new("Cat")
|> variant.with_argument(option.Some("name"), type_.string)
|> variant.with_argument(option.Some("has_catnip"), type_.bool)
})
use animal_type, dog_constructor, cat_constructor <- module.with_custom_type2(
definition.new("Animal") |> definition.with_publicity(True),
animals,
)
The type can be instantiated with custom.to_type.
The constructors can be used to create values of the type (constructor.to_expression)
or pattern match on values of the type (pattern.from_constructor).
To define a custom type with a dynamic number of variants, see with_custom_type_dynamic.
pub fn with_custom_type3(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(), a), b), c),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
) -> Module,
) -> Module
Define a custom type with three variants.
See with_custom_type1.
pub fn with_custom_type4(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(), a), b), c), d),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
) -> Module,
) -> Module
Define a custom type with four variants.
See with_custom_type1.
pub fn with_custom_type5(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(), a), b), c), d), e),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
) -> Module,
) -> Module
Define a custom type with five variants.
See with_custom_type1.
pub fn with_custom_type6(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(), a), b), c), d), e), f),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
) -> Module,
) -> Module
Define a custom type with six variants.
See with_custom_type1.
pub fn with_custom_type7(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
) -> Module,
) -> Module
Define a custom type with seven variants.
See with_custom_type1.
pub fn with_custom_type8(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g), h),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
constructor.Constructor(repr, h, generics),
) -> Module,
) -> Module
Define a custom type with eight variants.
See with_custom_type1.
pub fn with_custom_type9(
details: definition.Definition,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g), h), i),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
constructor.Constructor(repr, h, generics),
constructor.Constructor(repr, i, generics),
) -> Module,
) -> Module
Define a custom type with nine variants.
See with_custom_type1.
pub fn with_custom_type_dynamic(
details: definition.Definition,
type_: custom.CustomTypeBuilder(repr, type_.Dynamic, generics),
handler: fn(
custom.CustomType(repr, generics),
List(constructor.Constructor(repr, type_.Dynamic, generics)),
) -> Module,
) -> Module
Define a custom type with a dynamic number of variants.
See with_custom_type1.
pub fn with_dynamic_imports(
modules: List(import_.ImportedModule),
handler: fn(List(import_.ImportedModule)) -> Module,
) -> Module
pub fn with_function(
details: definition.Definition,
func: function.Function(func_type, ret),
handler: fn(expression.Expression(func_type)) -> Module,
) -> Module
pub fn with_import(
module: import_.ImportedModule,
handler: fn(import_.ImportReference) -> Module,
) -> Module
pub fn with_imported_custom_type1(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(repr, #(#(), a), generics),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
) -> Module,
) -> Module
Import a custom type with one variant.
use cat_module <- module.with_import(import_.new(["animal", "cat"]))
let cat =
custom.new()
|> custom.with_variant(fn(_) {
variant.new("Cat")
|> variant.with_argument(option.Some("name"), type_.string)
|> variant.with_argument(option.Some("age"), type_.int)
|> variant.with_argument(option.Some("has_catnip"), type_.bool)
})
use cat_type, cat_constructor <- module.with_imported_custom_type1(
cat_module,
"Cat"
cat,
)
The type can be instantiated with custom.to_type.
The constructors can be used to create values of the type (constructor.to_expression)
or pattern match on values of the type (pattern.from_constructor).
To define a custom type with a dynamic number of variants, see with_custom_type_dynamic.
pub fn with_imported_custom_type2(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(repr, #(#(#(), a), b), generics),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
) -> Module,
) -> Module
Import a custom type with two variants.
use option_module <- module.with_import(import_.new(["gleam", "option"]))
let option =
custom.new()
|> custom.with_generic("a")
|> custom.with_variant(fn(generics) {
let #(#(), a) = generics
variant.new("Some")
|> variant.with_argument(option.None, a)
})
|> custom.with_variant(fn(_generics) { variant.new("None") })
use option_type, some_constructor, none_constructor <- module.with_imported_custom_type2(
option_module,
"Option",
option,
)
The type can be instantiated with custom.to_type.
The constructors can be used to create values of the type (constructor.to_expression)
or pattern match on values of the type (pattern.from_constructor).
To import a custom type with a dynamic number of variants, see with_imported_custom_type_dynamic.
pub fn with_imported_custom_type3(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(), a), b), c),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
) -> Module,
) -> Module
Import a custom type with three variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type4(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(), a), b), c), d),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
) -> Module,
) -> Module
Import a custom type with four variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type5(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(), a), b), c), d), e),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
) -> Module,
) -> Module
Import a custom type with five variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type6(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(), a), b), c), d), e), f),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
) -> Module,
) -> Module
Import a custom type with six variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type7(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
) -> Module,
) -> Module
Import a custom type with seven variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type8(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g), h),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
constructor.Constructor(repr, h, generics),
) -> Module,
) -> Module
Import a custom type with eight variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type9(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(
repr,
#(#(#(#(#(#(#(#(#(#(), a), b), c), d), e), f), g), h), i),
generics,
),
handler: fn(
custom.CustomType(repr, generics),
constructor.Constructor(repr, a, generics),
constructor.Constructor(repr, b, generics),
constructor.Constructor(repr, c, generics),
constructor.Constructor(repr, d, generics),
constructor.Constructor(repr, e, generics),
constructor.Constructor(repr, f, generics),
constructor.Constructor(repr, g, generics),
constructor.Constructor(repr, h, generics),
constructor.Constructor(repr, i, generics),
) -> Module,
) -> Module
Import a custom type with nine variants.
See with_imported_custom_type1.
pub fn with_imported_custom_type_dynamic(
module: import_.ImportReference,
name: String,
type_: custom.CustomTypeBuilder(repr, type_.Dynamic, generics),
handler: fn(
custom.CustomType(repr, generics),
List(constructor.Constructor(repr, type_.Dynamic, generics)),
) -> Module,
) -> Module
Import a custom type with a dynamic number of variants.
See with_imported_custom_type1.
pub fn with_module_documentation_comments(
comments: List(String),
handler: fn() -> Module,
) -> Module
pub fn with_type_alias(
details: definition.Definition,
type_: type_.GeneratedType(repr),
handler: fn(type_.GeneratedType(repr)) -> Module,
) -> Module