<commit_before>-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Copyright 2016 [bk]door.maus

class Promise
	check: =>
		return false, "promise not implemented"

class TypePromise
	get_value_type: =>
		return type(@value)

	get_match: =>
		return @\get_value_type! == @name

	check: =>
		return @\get_match!, "expected '#{@name}', got #{@get_value_type!}"

Promise = {}
Promise.IsNumber = class extends TypePromise
	new: (value) =>
		@name = "number"
		@value = value

Promise.IsString = class extends TypePromise
	new: (value) =>
		@name = "string"
		@value = value

Promise.IsBoolean = class extends TypePromise
	new: (value) =>
		@name = "boolean"
		@value = value

Promise.IsTable = class extends TypePromise
	new: (value) =>
		@name = "table"
		@value = value

Promise.IsUserdata = class extends TypePromise
	new: (value) =>
		@name = "userdata"
		@value = value

Promise.IsClass = class extends TypePromise
	new: (value, object) =>
		@value = value
		@name = object.__name

	get_value_type: =>
		return @value.__class.__name

check_promise = (arg) ->
	if type(arg) == 'boolean' then
		return arg, "condition not met"
	else
		return arg\check!

Promise.keep = (message, ...) ->
	args = { n: select("#", ...), ... }
	for i = 1, args.n
		promise_kept, reason = check_promise(args[i])
		if not promise_kept
			error "#{message}: #{reason}", 2

Promise.keep_any = (message, ...) ->
	args = { n: select("#", ...), ... }
	for i = 1, args.n
		promise_kept, reason = check_promise(args[i])
		if promise_kept
			return
	error "#{message}: no promises kept", 2

return Promise<commit_msg>Added promise for objects of type function.<commit_after>-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Copyright 2016 [bk]door.maus

class Promise
	check: =>
		return false, "promise not implemented"

class TypePromise
	get_value_type: =>
		return type(@value)

	get_match: =>
		return @\get_value_type! == @name

	check: =>
		return @\get_match!, "expected '#{@name}', got #{@get_value_type!}"

Promise = {}
Promise.IsNumber = class extends TypePromise
	new: (value) =>
		@name = "number"
		@value = value

Promise.IsString = class extends TypePromise
	new: (value) =>
		@name = "string"
		@value = value

Promise.IsBoolean = class extends TypePromise
	new: (value) =>
		@name = "boolean"
		@value = value

Promise.IsTable = class extends TypePromise
	new: (value) =>
		@name = "table"
		@value = value

Promise.IsUserdata = class extends TypePromise
	new: (value) =>
		@name = "userdata"
		@value = value

Promise.IsClass = class extends TypePromise
	new: (value, object) =>
		@value = value
		@name = object.__name

	get_value_type: =>
		return @value.__class.__name

Promise.IsFunction = class extends TypePromise
	new: (value) =>
		@name = "function"
		@value = value

check_promise = (arg) ->
	if type(arg) == 'boolean' then
		return arg, "condition not met"
	else
		return arg\check!

Promise.keep = (message, ...) ->
	args = { n: select("#", ...), ... }
	for i = 1, args.n
		promise_kept, reason = check_promise(args[i])
		if not promise_kept
			error "#{message}: #{reason}", 2

Promise.keep_any = (message, ...) ->
	args = { n: select("#", ...), ... }
	for i = 1, args.n
		promise_kept, reason = check_promise(args[i])
		if promise_kept
			return
	error "#{message}: no promises kept", 2

return Promise
{'fraction_non_alphanumeric': 0.14984794028200166, 'fraction_numerical': 0.006635333149018523, 'mean_word_length': 3.528160200250313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '1042331', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1227, 'n_words': 381}