Explorer

definy.evaluate-pending-definitions

description
Evaluate the definitions with core.eval-value and turn the values into core.part-content (core.value-to-part-content), repeating while some are found (a definition part may itself be defined with a definition part)
type
Fn(
  pending: List<@definy.pending-definition>,
  contents: List<@definy.resolved-part-content>,
  external: List<Record{id: String, expression: @core.expression}>,
  evaluated: List<String>,
  then: Fn(contents: List<@definy.resolved-part-content>, evaluated: List<String>) -> @definy.service-io
) -> @definy.service-io
expression
fn(pending$0, contents$1, external$2, evaluated$3, then$4) =>
  match @core.equal(left: @core.list-length(value: $0), right: 0) {
    true =>
      $4(contents: $1, evaluated: $3),
    false =>
      let parts$5 = @core.list-concat(
          left: @core.list-fold(
            T: @definy.resolved-part-content,
            A: List<Record{id: String, expression: @core.expression}>,
            reducer: fn(acc$6, item$7) =>
              match $7.content.expression {
                #some(expression$8) =>
                  @core.list-append(list: $6, item: {id: $7.id, expression: $8}),
                #none(_) =>
                  $6
              },
            init: [],
            xs: $1
          ),
          right: $2
        );
      let contents$10 = @core.list-map(
          T: @definy.pending-definition,
          U: Union{#none, #some(@core.part-content)},
          f: fn(item$9) =>
            @core.value-to-part-content(value: @core.eval-value(expr: $9.definition, env: [], parts: $5)),
          xs: $0
        );
      let split$11 = @core.list-fold(
          T: @definy.pending-definition,
          A: Record{
            resolved: List<@definy.resolved-part-content>,
            remaining: List<@definy.pending-definition>,
            index: Number
          },
          reducer: fn(acc$12, item$13) =>
            match @core.list-get(list: $10, index: $12.index) {
              #some(#some(content$14)) =>
                {
                  resolved: @core.list-append(list: $12.resolved, item: {id: $13.id, content: $14}),
                  remaining: $12.remaining,
                  index: @core.plus(left: $12.index, right: 1)
                },
              _ =>
                {
                  resolved: $12.resolved,
                  remaining: @core.list-append(list: $12.remaining, item: $13),
                  index: @core.plus(left: $12.index, right: 1)
                }
            },
          init: {resolved: [], remaining: [], index: 0},
          xs: $0
        );
      match @core.equal(left: @core.list-length(value: $11.resolved), right: 0) {
        true =>
          $4(contents: $1, evaluated: $3),
        false =>
          @definy.evaluate-pending-definitions(
            pending: $11.remaining,
            contents: @core.list-concat(left: $1, right: $11.resolved),
            external: $2,
            evaluated: @core.list-concat(
              left: $3,
              right: @core.list-map(
                T: @definy.resolved-part-content,
                U: String,
                f: fn(item$15) =>
                  $15.id,
                xs: $11.resolved
              )
            ),
            then: fn(contents$16, evaluated$17) =>
              $4(contents: $16, evaluated: $17)
          )
      }
  }
visibility
public
definy.evaluate-pending-definitions (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: nACR6nzJyW74eEeD-uq_0BBmkSFnV3YZecoCgoF5vDQ
content hash: Ymg5Kyf00CFptnFS_9JMySCdCV7bOmXmlXwRy-wls-k