Explorer

core.union-variant-type-lookup

description
Lookup payload type by variant tag in union type variants
type
Fn(
  variants: List<Record{tag: String, payload_type: Union{#none, #some(@core.type-ast)}}>,
  tag: String,
  index: Number
) -> @core.type-result
expression
fn(variants$0, tag$1, index$2) =>
  match @core.list-get(list: $0, index: $2) {
    #none(_) =>
      #error(#variant_not_found({tag: $1})),
    #some(item$1011) =>
      match @core.equal(left: $1011.tag, right: $1) {
        true =>
          match $1011.payload_type {
            #none(_) =>
              #ok(#record([])),
            #some(t$10) =>
              #ok($10)
          },
        false =>
          @core.union-variant-type-lookup(variants: $0, tag: $1, index: @core.plus(left: $2, right: 1))
      }
  }
visibility
public
core.union-variant-type-lookup (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: WKw52TodNYqQCvvs1Rc2t4VfrIvD_UNbGD6NwYqYQXM
content hash: 12M-O8lM9MrYSsV0pfBcCsJJgAU1ePW6vgRuJF2G6mw