gleamgen/matcher
Types
Functions
pub fn bool_literal(literal: Bool) -> Matcher(Bool, Nil)
pub fn concat_string(
starting initial: String,
variable variable: String,
) -> Matcher(String, Expression(a))
Match a string that starts with initial
case_.new(expression.string("I love gleam"))
|> case_.with_matcher(
matcher.concat_string(starting: "I love ", variable: "thing"),
fn(thing) {
expression.string("I love ")
|> expression.concat_string(thing)
|> expression.concat_string(expression.string(" too"))
},
)
|> case_.with_matcher(matcher.variable("_"), fn(_) {
expression.string("interesting")
})
|> case_.build_expression()
|> expression.render(render.default_context())
|> render.to_string()
// -> "case \"I love gleam\" {
\"I love \" <> thing -> \"I love \" <> thing <> \" too\"
_ -> \"Interesting\"
}"
pub fn from_constructor0(
constructor: Constructor(a, #(), b),
) -> Matcher(a, Nil)
pub fn from_constructor1(
constructor: Constructor(a, #(#(), b), c),
first: Matcher(b, d),
) -> Matcher(CustomType(a, c), d)
pub fn from_constructor2(
constructor: Constructor(a, #(#(#(), b), c), d),
first: Matcher(b, e),
second: Matcher(c, f),
) -> Matcher(CustomType(a, d), #(e, f))
pub fn from_constructor3(
constructor: Constructor(a, #(#(#(#(), b), c), d), e),
first: Matcher(b, f),
second: Matcher(c, g),
third: Matcher(d, h),
) -> Matcher(a, #(f, g, h))
pub fn from_constructor4(
constructor: Constructor(a, #(#(#(#(#(), b), c), d), e), f),
first: Matcher(b, g),
second: Matcher(c, h),
third: Matcher(d, i),
fourth: Matcher(e, j),
) -> Matcher(a, #(g, h, i, j))
pub fn from_constructor5(
constructor: Constructor(
a,
#(#(#(#(#(#(), b), c), d), e), f),
g,
),
first: Matcher(b, h),
second: Matcher(c, i),
third: Matcher(d, j),
fourth: Matcher(e, k),
fifth: Matcher(f, l),
) -> Matcher(a, #(h, i, j, k, l))
pub fn from_constructor6(
constructor: Constructor(
a,
#(#(#(#(#(#(#(), b), c), d), e), f), g),
h,
),
first: Matcher(b, i),
second: Matcher(c, j),
third: Matcher(d, k),
fourth: Matcher(e, l),
fifth: Matcher(f, m),
sixth: Matcher(g, n),
) -> Matcher(a, #(i, j, k, l, m, n))
pub fn from_constructor7(
constructor: Constructor(
a,
#(#(#(#(#(#(#(#(), b), c), d), e), f), g), h),
i,
),
first: Matcher(b, j),
second: Matcher(c, k),
third: Matcher(d, l),
fourth: Matcher(e, m),
fifth: Matcher(f, n),
sixth: Matcher(g, o),
seventh: Matcher(h, p),
) -> Matcher(a, #(j, k, l, m, n, o, p))
pub fn from_constructor8(
constructor: Constructor(
a,
#(#(#(#(#(#(#(#(#(), b), c), d), e), f), g), h), i),
j,
),
first: Matcher(b, k),
second: Matcher(c, l),
third: Matcher(d, m),
fourth: Matcher(e, n),
fifth: Matcher(f, o),
sixth: Matcher(g, p),
seventh: Matcher(h, q),
eighth: Matcher(i, r),
) -> Matcher(a, #(k, l, m, n, o, p, q, r))
pub fn from_constructor9(
constructor: Constructor(
a,
#(#(#(#(#(#(#(#(#(#(), b), c), d), e), f), g), h), i), j),
k,
),
first: Matcher(b, l),
second: Matcher(c, m),
third: Matcher(d, n),
fourth: Matcher(e, o),
fifth: Matcher(f, p),
sixth: Matcher(g, q),
seventh: Matcher(h, r),
eighth: Matcher(i, s),
ninth: Matcher(j, t),
) -> Matcher(a, #(l, m, n, o, p, q, r, s, t))
pub fn get_output(matcher: Matcher(a, b)) -> b
pub fn int_literal(literal: Int) -> Matcher(Int, Nil)
pub fn or(
first: Matcher(a, b),
second: Matcher(a, b),
) -> Matcher(a, b)
Use either of the two matchers
case_.new(expression.string("hello"))
|> case_.with_matcher(
matcher.or(matcher.string_literal("hello"), matcher.string_literal("hi")),
fn(_) { expression.string("world") },
)
|> case_.with_matcher(matcher.variable("v"), fn(v) {
expression.concat_string(v, expression.string(" world"))
})
|> case_.build_expression()
|> expression.render(render.default_context())
|> render.to_string()
// -> "case \"hello\" {
\"hello\" | \"hi\" -> \"world\"
v -> v <> \" world\"
}",
pub fn string_literal(literal: String) -> Matcher(String, Nil)
pub fn to_unchecked(
type_: Matcher(a, b),
) -> Matcher(Unchecked, Unchecked)
pub fn tuple2(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
) -> Matcher(#(a, c), #(b, d))
pub fn tuple3(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
) -> Matcher(#(a, c, e), #(b, d, f))
pub fn tuple4(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
) -> Matcher(#(a, c, e, g), #(b, d, f, h))
pub fn tuple5(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
matcher5: Matcher(i, j),
) -> Matcher(#(a, c, e, g, i), #(b, d, f, h, j))
pub fn tuple6(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
matcher5: Matcher(i, j),
matcher6: Matcher(k, l),
) -> Matcher(#(a, c, e, g, i, k), #(b, d, f, h, j, l))
pub fn tuple7(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
matcher5: Matcher(i, j),
matcher6: Matcher(k, l),
matcher7: Matcher(m, n),
) -> Matcher(#(a, c, e, g, i, k, m), #(b, d, f, h, j, l, n))
pub fn tuple8(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
matcher5: Matcher(i, j),
matcher6: Matcher(k, l),
matcher7: Matcher(m, n),
matcher8: Matcher(o, p),
) -> Matcher(#(a, c, e, g, i, k, m, o), #(b, d, f, h, j, l, n, p))
pub fn tuple9(
matcher1: Matcher(a, b),
matcher2: Matcher(c, d),
matcher3: Matcher(e, f),
matcher4: Matcher(g, h),
matcher5: Matcher(i, j),
matcher6: Matcher(k, l),
matcher7: Matcher(m, n),
matcher8: Matcher(o, p),
matcher9: Matcher(q, r),
) -> Matcher(
#(a, c, e, g, i, k, m, o, q),
#(b, d, f, h, j, l, n, p, r),
)