gleamgen/matcher

Types

pub opaque type Matcher(input, match_output)

Functions

pub fn as_(
  original: Matcher(a, b),
  name: String,
) -> Matcher(a, Expression(a))
pub fn bool_literal(literal: Bool) -> Matcher(Bool, Nil)
pub fn from_constructor0(
  constructor: Construtor(a, #()),
) -> Matcher(a, Nil)
pub fn from_constructor1(
  constructor: Construtor(a, #(#(), b)),
  first: Matcher(b, c),
) -> Matcher(a, c)
pub fn from_constructor2(
  constructor: Construtor(a, #(#(#(), b), c)),
  first: Matcher(b, d),
  second: Matcher(c, e),
) -> Matcher(a, #(d, e))
pub fn from_constructor3(
  constructor: Construtor(a, #(#(#(#(), b), c), d)),
  first: Matcher(b, e),
  second: Matcher(c, f),
  third: Matcher(d, g),
) -> Matcher(a, #(e, f, g))
pub fn from_constructor4(
  constructor: Construtor(a, #(#(#(#(#(), b), c), d), e)),
  first: Matcher(b, f),
  second: Matcher(c, g),
  third: Matcher(d, h),
  fourth: Matcher(e, i),
) -> Matcher(a, #(f, g, h, i))
pub fn from_constructor5(
  constructor: Construtor(a, #(#(#(#(#(#(), b), c), d), e), f)),
  first: Matcher(b, g),
  second: Matcher(c, h),
  third: Matcher(d, i),
  fourth: Matcher(e, j),
  fifth: Matcher(f, k),
) -> Matcher(a, #(g, h, i, j, k))
pub fn from_constructor6(
  constructor: Construtor(
    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),
  sixth: Matcher(g, m),
) -> Matcher(a, #(h, i, j, k, l, m))
pub fn from_constructor7(
  constructor: Construtor(
    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),
  seventh: Matcher(h, o),
) -> Matcher(a, #(i, j, k, l, m, n, o))
pub fn from_constructor8(
  constructor: Construtor(
    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),
  eighth: Matcher(i, q),
) -> Matcher(a, #(j, k, l, m, n, o, p, q))
pub fn from_constructor9(
  constructor: Construtor(
    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),
  ninth: Matcher(j, s),
) -> Matcher(a, #(k, l, m, n, o, p, q, r, s))
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 render(matcher: Matcher(Unchecked, Unchecked)) -> Rendered
pub fn string_literal(literal: String) -> Matcher(String, Nil)
pub fn to_unchecked(
  type_: Matcher(a, b),
) -> Matcher(Unchecked, Unchecked)
pub fn tuple0() -> Matcher(#(), Nil)
pub fn tuple1(matcher: Matcher(a, b)) -> Matcher(#(a), #(b))
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),
)
pub fn variable(name: String) -> Matcher(a, Expression(a))
Search Document