<commit_before>"use strict"

const assert = require("assert")
const { "do": do_, Just, Nothing } = require("../index")

function* maybeComp(g, stack) {
  const results = []
  results.push(yield Just(1))
  results.push(yield Just(2))
  results.push(yield Just(3))
  if (g) {
    const inner = yield* do_(g, null, stack)
    if (Array.isArray(inner))
      Array.prototype.push.apply(results, inner)
    else
      results.push(inner)
  }
  return results
}

function* maybeCompFail() {
  const results = []
  results.push(yield Just(1))
  results.push(yield Nothing)
  results.push(yield Just(3))
  return results
}

describe("Maybe", function() {
  it("should return the result", done => {
    do_(maybeComp.bind(null, null), results => {
      assert.deepStrictEqual(results, [1, 2, 3])
      done()
    })
  })

  it("should return Nothing on failure", done => {
    do_(maybeCompFail, result => {
      assert.equal(result.isNothing(), true)
      done()
    })
  })

  it("should yield* from a successful computation", done => {
    do_(
      maybeComp.bind(null, maybeComp.bind(null, null)),
      results => {
        assert.deepStrictEqual(results, [1,2,3,1,2,3])
        done()
      }
    )
  })

  it("should yield* from a failing computation", done => {
    do_(
      maybeComp.bind(null, maybeCompFail),
      results => {
        assert.deepStrictEqual(results.slice(0, 3), [1,2,3])
        assert.strictEqual(results[3].isNothing(), true)
        done()
      }
    )
  })

  it("should yield* from yield* from a successful computation", done => {
    do_(
      maybeComp.bind(
        null,
        maybeComp.bind(
          null,
          maybeComp.bind(null, null)
        )
      ),
      results => {
        assert.deepStrictEqual(results, [1,2,3,1,2,3,1,2,3])
        done()
      })
  })

  it("should yield* from yield* from a failing computation", done => {
    do_(
      maybeComp.bind(
        null,
        maybeCompFail.bind(
          null,
          maybeCompFail
        )
      ),
      results => {
        assert.deepStrictEqual(results.slice(0,3), [1,2,3])
        assert.strictEqual(results[3].isNothing(), true)
        done()
      })
  })
})<commit_msg>tests/maybe: exports<commit_after>"use strict"

const assert = require("assert")
const { "do": do_, Just, Nothing } = require("../index")

function* maybeComp(g, stack) {
  const results = []
  results.push(yield Just(1))
  results.push(yield Just(2))
  results.push(yield Just(3))
  if (g) {
    const inner = yield* do_(g, null, stack)
    if (Array.isArray(inner))
      Array.prototype.push.apply(results, inner)
    else
      results.push(inner)
  }
  return results
}

function* maybeCompFail() {
  const results = []
  results.push(yield Just(1))
  results.push(yield Nothing)
  results.push(yield Just(3))
  return results
}

describe("Maybe", function() {
  it("should return the result", done => {
    do_(maybeComp.bind(null, null), results => {
      assert.deepStrictEqual(results, [1, 2, 3])
      done()
    })
  })

  it("should return Nothing on failure", done => {
    do_(maybeCompFail, result => {
      assert.equal(result.isNothing(), true)
      done()
    })
  })

  it("should yield* from a successful computation", done => {
    do_(
      maybeComp.bind(null, maybeComp.bind(null, null)),
      results => {
        assert.deepStrictEqual(results, [1,2,3,1,2,3])
        done()
      }
    )
  })

  it("should yield* from a failing computation", done => {
    do_(
      maybeComp.bind(null, maybeCompFail),
      results => {
        assert.deepStrictEqual(results.slice(0, 3), [1,2,3])
        assert.strictEqual(results[3].isNothing(), true)
        done()
      }
    )
  })

  it("should yield* from yield* from a successful computation", done => {
    do_(
      maybeComp.bind(
        null,
        maybeComp.bind(
          null,
          maybeComp.bind(null, null)
        )
      ),
      results => {
        assert.deepStrictEqual(results, [1,2,3,1,2,3,1,2,3])
        done()
      })
  })

  it("should yield* from yield* from a failing computation", done => {
    do_(
      maybeComp.bind(
        null,
        maybeCompFail.bind(
          null,
          maybeCompFail
        )
      ),
      results => {
        assert.deepStrictEqual(results.slice(0,3), [1,2,3])
        assert.strictEqual(results[3].isNothing(), true)
        done()
      })
  })
})

module.exports = {
  maybeComp,
  maybeCompFail,
}
{'fraction_non_alphanumeric': 0.15225690545699527, 'fraction_numerical': 0.01571973950145969, 'mean_word_length': 2.4393822393822395, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 27, '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': '4352052', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1440, 'n_words': 302}