Explorer

core.list-map-inner

description
f applied to the items of xs from start (inclusive) to end (exclusive), in order (f is called in the order of the items). Splits the range in halves, so an item goes through O(log n) wrapping lambdas and the lists are copied O(n log n) in all (one item at a time with list-append, both were O(n^2))
type
Fn(
  T: Type,
  U: Type,
  f: Fn(item: Param("T")) -> Param("U"),
  xs: List<Param("T")>,
  start: Number,
  end: Number
) -> List<Param("U")>
expression
fn(T$0, U$1, f$2, xs$3, start$4, end$5) =>
  let length$6 = @core.minus(left: $5, right: $4);
  match @core.less-than(left: $6, right: 2) {
    true =>
      match @core.equal(left: $6, right: 1) {
        true =>
          match @core.list-get(list: $3, index: $4) {
            #some(item$7) =>
              [$2(item: $7)],
            #none(_) =>
              []
          },
        false =>
          []
      },
    false =>
      let middle$8 = @core.plus(left: $4, right: @core.divide(left: $6, right: 2));
      let left$9 = @core.list-map-inner(
          T: $0,
          U: $1,
          f: fn(item$10) =>
            $2(item: $10),
          xs: $3,
          start: $4,
          end: $8
        );
      @core.list-concat(
        left: $9,
        right: @core.list-map-inner(
          T: $0,
          U: $1,
          f: fn(item$11) =>
            $2(item: $11),
          xs: $3,
          start: $8,
          end: $5
        )
      )
  }
visibility
public
core.list-map-inner (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: xm_v8tBRmAiUeAeopw2NpW0fT8HtemRVGvfpc08dcvo
content hash: _nmRQURWb8dtFTdheR7nj_ZdzB6xd1dH7lFCqLNxFYw