Explorer

definy.collect-evaluation-parts

description
Follow the references from frontier and read the expressions of the parts outside the snapshot the evaluator uses (read_part_definitions. Only definitions read without the evaluator)
type
Fn(
  frontier: List<String>,
  seen: List<String>,
  external: List<Record{id: String, expression: @core.expression}>,
  sources: List<@definy.snapshot-check-source-part>,
  contents: List<@definy.resolved-part-content>,
  then: Fn(external: List<Record{id: String, expression: @core.expression}>) -> @definy.service-io
) -> @definy.service-io
expression
fn(frontier$0, seen$1, external$2, sources$3, contents$4, then$5) =>
  let step$6 = @core.list-fold(
      T: String,
      A: Record{seen: List<String>, next: List<String>, to_read: List<String>},
      reducer: fn(acc$7, item$8) =>
        match @core.list-contains-string(list: $7.seen, target: $8, index: 0) {
          true =>
            $7,
          false =>
            match @definy.source-part-find(parts: $3, id: $8, index: 0) {
              #some(source$9) =>
                {
                  seen: @core.list-append(list: $7.seen, item: $8),
                  next: match @definy.resolved-content-find(contents: $4, id: $8, index: 0) {
                    #some(content$10) =>
                      match $10.expression {
                        #some(expression$11) =>
                          @definy.evaluated-part-references(expr: $11, ids: $7.next),
                        #none(_) =>
                          $7.next
                      },
                    #none(_) =>
                      match $9.definition {
                        #some(definition$12) =>
                          @definy.evaluated-part-references(expr: $12, ids: $7.next),
                        #none(_) =>
                          $7.next
                      }
                  },
                  to_read: $7.to_read
                },
              #none(_) =>
                {
                  seen: @core.list-append(list: $7.seen, item: $8),
                  next: $7.next,
                  to_read: @core.list-append(list: $7.to_read, item: $8)
                }
            }
        },
      init: {seen: $1, next: [], to_read: []},
      xs: $0
    );
  match @core.equal(left: @core.list-length(value: $6.to_read), right: 0) {
    true =>
      match @core.equal(left: @core.list-length(value: $6.next), right: 0) {
        true =>
          $5(external: $2),
        false =>
          @definy.collect-evaluation-parts(
            frontier: $6.next,
            seen: $6.seen,
            external: $2,
            sources: $3,
            contents: $4,
            then: fn(external$13) =>
              $5(external: $13)
          )
      },
    false =>
      @definy.read-part-definitions(
        part_ids: $6.to_read,
        then: fn(definitions$14) =>
          let read$15 = @core.list-fold(
              T: String,
              A: Record{
                external: List<Record{id: String, expression: @core.expression}>,
                next: List<String>,
                index: Number
              },
              reducer: fn(acc$16, item$17) =>
                let added$18 = match @core.list-get(list: $14, index: $16.index) {
                    #some(#some(definition$19)) =>
                      match @definy.immediate-part-content(definition: $19) {
                        #some(#some(content$20)) =>
                          match $20.expression {
                            #some(expression$21) =>
                              {
                                external: @core.list-append(list: $16.external, item: {id: $17, expression: $21}),
                                next: @definy.evaluated-part-references(expr: $21, ids: $16.next)
                              },
                            #none(_) =>
                              {external: $16.external, next: $16.next}
                          },
                        _ =>
                          {external: $16.external, next: $16.next}
                      },
                    _ =>
                      {external: $16.external, next: $16.next}
                  };
                {external: $18.external, next: $18.next, index: @core.plus(left: $16.index, right: 1)},
              init: {external: $2, next: $6.next, index: 0},
              xs: $6.to_read
            );
          @definy.collect-evaluation-parts(
            frontier: $15.next,
            seen: $6.seen,
            external: $15.external,
            sources: $3,
            contents: $4,
            then: fn(external$22) =>
              $5(external: $22)
          )
      )
  }
visibility
public
definy.collect-evaluation-parts (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: jghVChyNQeVdTTWn1DjjkjQyDaiHaHiDhhbra74KiLA
content hash: EzA0-l04XAJq0rTlEjmeg7Xnwkm3GOD7vyF1eWDGZ9E