nonEmpty
nonEmpty<T extends {} | {}>(reason?: string): Object
Type Parameters
Parameters
reason: string = 'NonEmpty'
Returns Object
Example
import * as x from 'unhoax'
import pipe from 'just-pipe'
// With a Set
const nonEmpty = x.nonEmpty('optional reason')
const mySet = nonEmpty(x.Set(x.string)) // SetSchema<string>
// or, using pipe:
const mySet = pipe(x.string, x.Set, x.nonEmpty()) // SetSchema<string>
// With a string
const firstName = x.nonEmpty('NonEmpty')(x.string) // Schema<string>
class LinkedList<T> {
get length(): number { … }
static fromArray = <T>(array: T[]): LinkedList<T> => { … }
}
// With a custom type
const LinkedListSchema = <T>(itemSchema: Schema<T>) => pipe(
x.array(itemSchema),
x.map(LinkedList.fromArray),
x.nonEmpty('NonEmpty'),
) // Schema<LinkedList<T>>
Works on anything with a size or length property of type number.
Commonly known: array, set, map and strings
It could also be your own types.