uncertainty
The Uncertainty object is an uncertain data having a definite value when measured. It is inspired by quantum machanics and borrows a concept that an observation collapses a wave function and reduces to a state of particles of Copenhagen interpretation.
Getting Started
npm i -S uncertainty
const Uncertainty = ; const isBottleBroken = const cat = isBottleBroken console // Uncertainconsole // Uncertainconsole // dead or aliveconsole // Measuredconsole // Measured
API
new Uncertainty(arg?: any[])
An Uncertainty constructor creates new Uncertainty object. It receives a range of probable values as an array.
const a = console // true or false const b = 1 2 3console // 1, 2 or 3
.then(cb: Function)
.then()
receives a callback function which is run when the value is measured. The function will always be run before a measuring code.
const a = 1 2aconsole // Hello, world!// 2
.then()
also creates a new Uncertainty object entangled with the object. The callback function receives the entangled object as an input, and returns new Uncertainty object value. When one of the entangled objects are measured, the other are also measured.
const a = const b = aconst c = bconsole // Uncertainconsole // Uncertainconsole // Uncertainconsole // false or trueconsole // Measuredconsole // Measuredconsole // Measured
.peek()
.peek()
peeks the data state whether it is uncertain or measured. It does not measure the value.
const a = console // Uncertainconsole // true or falseconsole // Measured
Measurement
Measurement means access to a data value. If it does not have to access a value, it is considered unmeasured. For example, in a conditional statement, an Uncertainty object has same characteristics as a JavaScript object.
const a = a // Not measured.!a // Not measured. An object in JavsScript is always trusty.a + 1 // Measured.a == true // Measured. It is calcuated after type casting.a === true // Not measured. It does not have to measure a value because of different types.