<commit_before>//! @isthmus/atom - Copyright (c) 2017, <NAME>; This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree
import R from 'ramda'

if (process.env.NODE_ENV !== 'production') {
  var assert = require('./assert')
}

export var HALT = '@@isthmus/atom/halt'
export var TYPES = {
  ATOM: '@@isthmus/atom',
  COMPUTED: '@@isthmus/atom/computed',
  LENSED: '@@isthmus/atom/lensed',
  ENDED: '@@isthmus/atom/ended'
}

export var end = R.curry(_end)
export var isAtom = R.curry(_isAtom)
export var combine = R.curry(_combine)

function _isAtom (atom) {
  return Boolean(atom && atom.isAtom)
}

export function log () {
  var il = arguments.length
  var result = Array(il)

  for (var i = 0; i < il; ++i) {
    var item = arguments[i]
    result[i] = _isAtom(item) ? item.value : item
  }

  console.log.apply(console, result)
}

function addToSinkStack (stack, sinks) {
  for (var i = 0, il = sinks.length; i < il; ++i) {
    var sink = sinks[i]
    if (sink.updateIndex !== null) {
      for (var j = sink.updateIndex, jl = stack.length; j < jl; ++j) {
        stack[j] = stack[j + 1]
      }
      stack[sink.updateIndex = stack.length - 1] = sink
    } else {
      stack[sink.updateIndex = stack.length] = sink
    }

    addToSinkStack(stack, sink.sinks)
  }
  return stack
}

function preventOffspring (sinks) {
  for (var i = 0, il = sinks.length; i < il; ++i) {
    sinks[i].updateIndex = null
    preventOffspring(sinks[i].sinks)
  }
}

function updateSinks (value, atom) {
  if (atom.readonly) {
    throw new Error('Cannot manually set readonly atom')
  }

  if (value === HALT) {
    throw new Error('Cannot manually set HALT')
  }

  if (atom.type === TYPES.LENSED) {
    value = R.set(atom.lens, value, atom.source.value)
    atom = atom.source
  }

  atom.updateIndex = -1
  atom.value = value

  const stack = addToSinkStack([], atom.sinks)

  for (var i = 0, il = stack.length; i < il; ++i) {
    var item = stack[i]
    if (item.updateIndex !== null) {
      item.update()
      if (item.value === HALT) {
        preventOffspring(item.sinks)
      }
    }
  }

  for (var j = 0, jl = stack.length; j < jl; ++j) {
    stack[j].updateIndex = null
  }

  atom.updateIndex = null
}

function _end (atom) {
  if (process.env.NODE_ENV !== 'production') {
    assert.isAtom('end', atom)
  }

  for (var i = 0, il = atom.sources.length; i < il; ++i) {
    var source = atom.sources[i]
    var index = source.sinks.indexOf(atom)
    source.sinks.splice(index, 1)
  }

  for (var j = 0, jl = atom.sinks.length; j < jl; ++j) {
    _end(atom.sinks[j])
  }

  atom.type = TYPES.ENDED
  atom.readonly = true
  atom.value = null
  atom.update = null
  atom.compute = null
  atom.lens = null
  atom.source = null
  atom.sources = []
}

function toJSON (atom) {
  return atom.value != null && typeof atom.value.toJSON === 'function'
    ? atom.value.toJSON()
    : atom.value
}
function valueOf (atom) {
  return atom.value
}

export var Atom = function Atom (value) {
  atom.isAtom = true
  atom.type = TYPES.ATOM
  atom.readonly = false
  atom.value = value
  atom.sinks = []

  atom.updateIndex = null

  atom.sources = []
  atom.update = null
  atom.compute = null
  atom.lens = null
  atom.source = null

  atom.map = R.flip(map)(atom)
  atom.view = R.flip(view)(atom)
  atom.scan = scan(R.__, R.__, atom)
  atom.modify = R.flip(scan)(atom)
  atom.end = _end.bind(null, atom)
  atom.log = log.bind(null, atom)

  atom.toJSON = toJSON.bind(null, atom)
  atom.valueOf = valueOf.bind(null, atom)
  atom.toString = atom.valueOf

  return atom
  function atom () {
    return arguments.length > 0
      ? (updateSinks(arguments[0], atom), atom)
      : atom.value
  }
}

export default Atom

function _combine (compute, sources) {
  if (process.env.NODE_ENV !== 'production') {
    assert.isAtomList('combine', sources)
  }
  var atom = Atom()
<commit_msg>save a few bytes<commit_after>//! @isthmus/atom - Copyright (c) 2017, <NAME>; This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree
import R from 'ramda'

if (process.env.NODE_ENV !== 'production') {
  var assert = require('./assert')
}

export var HALT = '@@isthmus/atom/halt'
export var TYPES = {
  ATOM: '@@isthmus/atom',
  COMPUTED: '@@isthmus/atom/computed',
  LENSED: '@@isthmus/atom/lensed',
  ENDED: '@@isthmus/atom/ended'
}

export var end = R.curry(_end)
export var isAtom = R.curry(_isAtom)
export var combine = R.curry(_combine)

function _isAtom (atom) {
  return Boolean(atom && atom.isAtom)
}

export function log () {
  var il = arguments.length
  var result = Array(il)

  for (var i = 0; i < il; ++i) {
    var item = arguments[i]
    result[i] = _isAtom(item) ? item.value : item
  }

  console.log.apply(console, result)
}

function addToSinkStack (stack, sinks) {
  for (var i = 0, il = sinks.length; i < il; ++i) {
    var sink = sinks[i]
    if (sink.updateIndex !== null) {
      for (var j = sink.updateIndex, jl = stack.length; j < jl; ++j) {
        stack[j] = stack[j + 1]
      }
      stack[sink.updateIndex = stack.length - 1] = sink
    } else {
      stack[sink.updateIndex = stack.length] = sink
    }

    addToSinkStack(stack, sink.sinks)
  }
  return stack
}

function preventOffspring (sinks) {
  for (var i = 0, il = sinks.length; i < il; ++i) {
    sinks[i].updateIndex = null
    preventOffspring(sinks[i].sinks)
  }
}

function updateSinks (value, atom) {
  if (atom.readonly) {
    throw new Error('Cannot manually set readonly atom')
  }

  if (value === HALT) {
    throw new Error('Cannot manually set HALT')
  }

  if (atom.type === TYPES.LENSED) {
    value = R.set(atom.lens, value, atom.source.value)
    atom = atom.source
  }

  atom.updateIndex = -1
  atom.value = value

  const stack = addToSinkStack([], atom.sinks)

  for (var i = 0, il = stack.length; i < il; ++i) {
    var item = stack[i]
    if (item.updateIndex !== null) {
      item.update()
      if (item.value === HALT) {
        preventOffspring(item.sinks)
      }
    }
  }

  for (var j = 0, jl = stack.length; j < jl; ++j) {
    stack[j].updateIndex = null
  }

  atom.updateIndex = null
}

function _end (atom) {
  if (process.env.NODE_ENV !== 'production') {
    assert.isAtom('end', atom)
  }

  for (var i = 0, il = atom.sources.length; i < il; ++i) {
    var source = atom.sources[i]
    var index = source.sinks.indexOf(atom)
    source.sinks.splice(index, 1)
  }

  for (var j = 0, jl = atom.sinks.length; j < jl; ++j) {
    _end(atom.sinks[j])
  }

  atom.type = TYPES.ENDED
  atom.readonly = true
  atom.value = null
  atom.update = null
  atom.compute = null
  atom.lens = null
  atom.source = null
  atom.sources = []
}

function toJSON (atom) {
  return atom.value != null && typeof atom.value.toJSON === 'function'
    ? atom.value.toJSON()
    : atom.value
}
function valueOf (atom) {
  return atom.value
}

export var Atom = function Atom (value) {
  atom.isAtom = true
  atom.type = TYPES.ATOM
  atom.readonly = false
  atom.value = value
  atom.sinks = []

  atom.updateIndex = null

  atom.sources = []
  atom.update = null
  atom.compute = null
  atom.lens = null
  atom.source = null

  atom.map = map(R.__, atom)
  atom.view = view(R.__, atom)
  atom.scan = scan(R.__, R.__, atom)
  atom.modify = scan(R.__, atom)
  atom.end = _end.bind(null, atom)
  atom.log = log.bind(null, atom)

  atom.toJSON = toJSON.bind(null, atom)
  atom.valueOf = valueOf.bind(null, atom)
  atom.toString = atom.valueOf

  return atom
  function atom () {
    return arguments.length > 0
      ? (updateSinks(arguments[0], atom), atom)
      : atom.value
  }
}

export default Atom

function _combine (compute, sources) {
  if (process.env.NODE_ENV !== 'production') {
    assert.isAtomList('combine', sources)
  }
  var atom = Atom()

{'fraction_non_alphanumeric': 0.14831317632081475, 'fraction_numerical': 0.004328453214513049, 'mean_word_length': 2.8871845620979713, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, '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': '4280855', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2884, 'n_words': 742}