cedric-demongivert / unidoc

A reactive parser written in typescript for a LaTeX and XML inspired tag language.
GNU General Public License v3.0
1 stars 0 forks source link

Adding a factory to the Validator API for providing a fully functional way to map a Symbol producer into a Validation producer. #1

Closed cedric-demongivert closed 3 years ago

cedric-demongivert commented 3 years ago

A factory for mapping a Symbol producer into a Validation producer is missing from the Validator namespace.

The following code is the current way to map a stream of symbol into a stream of validation (from a Kiss validator) :

const source: UnidocProducer<UnidocSymbol> = anySymbolProducer()
const events: UnidocProducer<UnidocEvent> = parse(tokenize(source))

const validator: UnidocValidator = UnidocValidator.kiss(factory())
validator.subscribe(events) // <-- this line denote is an UX problem

Ideally the library must allow to write the following code:

const source: UnidocProducer<UnidocSymbol> = anySymbolProducer()
const events: UnidocProducer<UnidocEvent> = parse(tokenize(source))
const validator: UnidocProducer<UnidocValidation>= UnidocValidator.kiss(events, factory())

Or:

const source: UnidocProducer<UnidocSymbol> = anySymbolProducer()
const events: UnidocProducer<UnidocEvent> = parse(tokenize(source))
const validator: UnidocProducer<UnidocValidation>= UnidocValidator.validate(events, validator)