<commit_before>/**
 * Created by <NAME> on 27.12.2016.
 */

import Range1D from './Range1D';
import CompositeRange1D from './CompositeRange1D';
import Range1DGroup from './Range1DGroup';
import {all, default as Range, none} from './Range';
import parseRange from './parser';
export {default as Range, all, none} from './Range';
export {default as Range1D} from './Range1D';
export {default as CompositeRange1D} from './CompositeRange1D';
export {default as Range1DGroup} from './Range1DGroup';


/**
 * Creates a new range starting at from and optionally up to 'to' and optionally with a step
 * @param from the index where the range starts (included)
 * @param to the index where the range ends (excluded), defaults to the end of the data structure
 * @param step the step size, defaults to 1
 */
export function range(from: number, to?: number, step?: number): Range;
/**
 * Creates a new multidimensional range.
 * @param ranges Each array can contain up to three indices, the first is read as 'from',
 * the second as 'to' and the third as 'step'.
 */
export function range(...ranges: number[][]): Range;
/**
 * Creates a new range that includes all elements in the data structure
 * @returns {any}
 */
export function range() {
  if (arguments.length === 0) {
    return all();
  }
  const r = new Range();
  if (Array.isArray(arguments[0])) { //array mode
    Array.from(arguments).forEach((arr: number[], i) => {
      if (arr.length === 0) {
        return;
      }
      r.dim(i).setSlice(arr[0], arr[1], arr[2]);
    });
  }
  if (typeof arguments[0] === 'number') { //single slice mode
    r.dim(0).setSlice(arguments[0], arguments[1], arguments[2]);
  }
  return r;
}
/**
 * Joins the specified ranges into a multidimensional range. If no ranges are provides as parameter,
 * returns a new range that includes all elements.
 * @param ranges the ranges to be joined. If the supplied range is a multidimensional range,
 * then the first one is used, the rest is ignored
 * @return a multidimensional range
 */
export function join(ranges: Range[]): Range;
export function join(...ranges: Range[]): Range;
export function join() {
  if (arguments.length === 0) {
    return all();
  }
  let ranges = arguments[0];
  if (!Array.isArray(ranges)) { //array mode
    ranges = Array.from(arguments);
  }
  return new Range(ranges.map((r: Range) => r.dim(0)));
}

/**
 * TODO: document
 * @param dimsOrIndicesOrIndexArray
 */
export function list(...dimsOrIndicesOrIndexArray: (Range1D | number[] | number)[]): Range;
export function list(dims: Range1D[]): Range;
export function list(): Range {
  if (arguments.length === 0) {
    return all();
  }
  if (Array.isArray(arguments[0]) && arguments[0][0] instanceof Range1D) {
    return new Range(arguments[0]);
  } else if (Array.isArray(arguments[0])) { //array mode
    const r = new Range();
    Array.from(arguments).forEach((arr: any, i) => {
      if (arr instanceof Range1D) {
        r.dims[i] = arr;
      } else {
        r.dim(i).setList(arr);
      }
    });
    return r;
  } else if (typeof arguments[0] === 'number') { //single slice mode
    const r = new Range();
    r.dim(0).setList(Array.from(arguments));
    return r;
  } else if (arguments[0] instanceof Range1D) {
    return new Range(Array.from(arguments));
  }
  return none();
}


export function asUngrouped(range: Range1D) {
  return new Range1DGroup('unnamed', 'gray', range);
}

export function composite(name: string, groups: Range1DGroup[]) {
  return new CompositeRange1D(name, groups);
}

/**
 * Tests if the given object is a range
 */
export function is(obj: any) {
  return obj instanceof Range;
}

/**
 * something that can be parsed as a range
 */
export type RangeLike = Range | number[] | number[][] | string;

/**
 * parses the given encoded string created by toString to a range object
 * @param arange something like a range
 * @returns {Range}
 */
export function parse(arange: RangeLike = null) {

  if (arange === null) {
    return all();
  }
  if (arange instanceof Range) {
    return <Range>arange;
  }
  if (Array.isArray(arange)) {
    if (Array.isArray(arange[0])) {
      return list(...<number[][]>arange);
    }
    return list(<number[]>arange);
  }
  //join given array as string combined with ,
  return parseRange(Array.from(arguments).map(String).join(','));
}

export function cell(...dimIndices: number[]) {
  return new Range(dimIndices.map(Range1D.single));
}
<commit_msg>documenting join fixes<commit_after>/**
 * Created by <NAME> on 27.12.2016.
 */

import Range1D from './Range1D';
import CompositeRange1D from './CompositeRange1D';
import Range1DGroup from './Range1DGroup';
import {all, default as Range, none} from './Range';
import parseRange from './parser';
export {default as Range, all, none} from './Range';
export {default as Range1D} from './Range1D';
export {default as CompositeRange1D} from './CompositeRange1D';
export {default as Range1DGroup} from './Range1DGroup';


/**
 * Creates a new range starting at from and optionally up to 'to' and optionally with a step
 * @param from the index where the range starts (included)
 * @param to the index where the range ends (excluded), defaults to the end of the data structure
 * @param step the step size, defaults to 1
 */
export function range(from: number, to?: number, step?: number): Range;
/**
 * Creates a new multidimensional range.
 * @param ranges Each array can contain up to three indices, the first is read as 'from',
 * the second as 'to' and the third as 'step'.
 */
export function range(...ranges: number[][]): Range;
/**
 * Creates a new range that includes all elements in the data structure
 * @returns {any}
 */
export function range() {
  if (arguments.length === 0) {
    return all();
  }
  const r = new Range();
  if (Array.isArray(arguments[0])) { //array mode
    Array.from(arguments).forEach((arr: number[], i) => {
      if (arr.length === 0) {
        return;
      }
      r.dim(i).setSlice(arr[0], arr[1], arr[2]);
    });
  }
  if (typeof arguments[0] === 'number') { //single slice mode
    r.dim(0).setSlice(arguments[0], arguments[1], arguments[2]);
  }
  return r;
}
/**
 * Joins the specified ranges into a multidimensional range. If no ranges are provided as parameter,
 * returns a new range that includes all elements.
 * @param ranges the ranges to be joined. If the supplied range is a multidimensional range,
 * then the first one is used, the rest is ignored.
 * @return a multidimensional range.
 */
export function join(ranges: Range[]): Range;
export function join(...ranges: Range[]): Range;
export function join() {
  if (arguments.length === 0) {
    return all();
  }
  let ranges = arguments[0];
  if (!Array.isArray(ranges)) { //array mode
    ranges = Array.from(arguments);
  }
  return new Range(ranges.map((r: Range) => r.dim(0)));
}

/**
 * TODO: document
 * @param dimsOrIndicesOrIndexArray
 */
export function list(...dimsOrIndicesOrIndexArray: (Range1D | number[] | number)[]): Range;
export function list(dims: Range1D[]): Range;
export function list(): Range {
  if (arguments.length === 0) {
    return all();
  }
  if (Array.isArray(arguments[0]) && arguments[0][0] instanceof Range1D) {
    return new Range(arguments[0]);
  } else if (Array.isArray(arguments[0])) { //array mode
    const r = new Range();
    Array.from(arguments).forEach((arr: any, i) => {
      if (arr instanceof Range1D) {
        r.dims[i] = arr;
      } else {
        r.dim(i).setList(arr);
      }
    });
    return r;
  } else if (typeof arguments[0] === 'number') { //single slice mode
    const r = new Range();
    r.dim(0).setList(Array.from(arguments));
    return r;
  } else if (arguments[0] instanceof Range1D) {
    return new Range(Array.from(arguments));
  }
  return none();
}


export function asUngrouped(range: Range1D) {
  return new Range1DGroup('unnamed', 'gray', range);
}

export function composite(name: string, groups: Range1DGroup[]) {
  return new CompositeRange1D(name, groups);
}

/**
 * Tests if the given object is a range
 */
export function is(obj: any) {
  return obj instanceof Range;
}

/**
 * something that can be parsed as a range
 */
export type RangeLike = Range | number[] | number[][] | string;

/**
 * parses the given encoded string created by toString to a range object
 * @param arange something like a range
 * @returns {Range}
 */
export function parse(arange: RangeLike = null) {

  if (arange === null) {
    return all();
  }
  if (arange instanceof Range) {
    return <Range>arange;
  }
  if (Array.isArray(arange)) {
    if (Array.isArray(arange[0])) {
      return list(...<number[][]>arange);
    }
    return list(<number[]>arange);
  }
  //join given array as string combined with ,
  return parseRange(Array.from(arguments).map(String).join(','));
}

export function cell(...dimIndices: number[]) {
  return new Range(dimIndices.map(Range1D.single));
}

{'fraction_non_alphanumeric': 0.1461495222034851, 'fraction_numerical': 0.012366498032602586, 'mean_word_length': 3.6212987012987012, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4767869', 'n_tokens_mistral': 2759, 'n_tokens_neox': 2735, 'n_words': 956}