<commit_before>import Properties from './Properties';
import Up from './Up';
import { Arr } from '@ephox/katamari';
import { Option } from '@ephox/katamari';

var extract = function (item) {
  var self = item.id;
  var rest = item.children && item.children.length > 0 ? Arr.bind(item.children, extract) : [];
  return [ self ].concat(rest);
};

var comparePosition = function (item, other) {
  // horribly inefficient
  var top = Up.top(item);
  var all = extract(top);

  var itemIndex = Arr.findIndex(all, function (x) { return item.id === x; });
  var otherIndex = Arr.findIndex(all, function (x) { return other.id === x; });
  return itemIndex.bind(function (iIndex) {
    return otherIndex.map(function (oIndex) {
      if (iIndex < oIndex) return 4;
      else return 2;
    });
  }).getOr(0);
};

var prevSibling = function (item) {
  var parent = Properties.parent(item);
  var kin = parent.map(Properties.children).getOr([]);
  var itemIndex = Arr.findIndex(kin, function (x) { return item.id === x.id; });
  return itemIndex.bind(function (iIndex) {
    return iIndex > 0 ? Option.some(kin[iIndex - 1]) : Option.none();
  });
};

var nextSibling = function (item) {
  var parent = Properties.parent(item);
  var kin = parent.map(Properties.children).getOr([]);
  var itemIndex = Arr.findIndex(kin, function (x) { return item.id === x.id; });
  return itemIndex.bind(function (iIndex) {
    return iIndex < kin.length - 1 ? Option.some(kin[iIndex + 1]) : Option.none();
  });
};

export default <any> {
  comparePosition: comparePosition,
  prevSibling: prevSibling,
  nextSibling: nextSibling
};<commit_msg>TINY-1615: fix errors caused by typing katamari Arr<commit_after>import Properties from './Properties';
import Up from './Up';
import { Arr } from '@ephox/katamari';
import { Option } from '@ephox/katamari';

var extract = function (item) {
  var self = item.id;
  var rest = item.children && item.children.length > 0 ? Arr.bind(item.children, extract) : [];
  return [ self ].concat(rest);
};

var comparePosition = function (item, other) {
  // horribly inefficient
  var top = Up.top(item);
  var all = extract(top);

  var itemIndex = Arr.findIndex(all, function (x) { return item.id === x; });
  var otherIndex = Arr.findIndex(all, function (x) { return other.id === x; });
  return itemIndex.bind(function (iIndex) {
    return otherIndex.map(function (oIndex): number {
      if (iIndex < oIndex) return 4;
      else return 2;
    });
  }).getOr(0);
};

var prevSibling = function (item) {
  var parent = Properties.parent(item);
  var kin = parent.map(Properties.children).getOr([]);
  var itemIndex = Arr.findIndex(kin, function (x) { return item.id === x.id; });
  return itemIndex.bind(function (iIndex) {
    return iIndex > 0 ? Option.some(kin[iIndex - 1]) : Option.none();
  });
};

var nextSibling = function (item) {
  var parent = Properties.parent(item);
  var kin = parent.map(Properties.children).getOr([]);
  var itemIndex = Arr.findIndex(kin, function (x) { return item.id === x.id; });
  return itemIndex.bind(function (iIndex) {
    return iIndex < kin.length - 1 ? Option.some(kin[iIndex + 1]) : Option.none();
  });
};

export default <any> {
  comparePosition: comparePosition,
  prevSibling: prevSibling,
  nextSibling: nextSibling
};
{'fraction_non_alphanumeric': 0.1600609756097561, 'fraction_numerical': 0.006097560975609756, 'mean_word_length': 3.8679525222551927, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '657614', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1093, 'n_words': 290}