Variable: get()
const
get: <Value
>(iterable
) =>Value
Defined in: optionals.d.ts:190
Returns the only value in iterable
if it contains exactly one value.
Otherwise, throws an error.
Type Parameters
Value
Value
Parameters
iterable
Iterable
<Value
>
Returns
Value
Example
import { get } from 'lfi'
console.log(get([`sloth`]))
//=> sloth
try {
console.log(get([]))
} catch {
console.log(`Oh no! It was empty...`)
}
//=> Oh no! It was empty...
try {
console.log(get([`sloth`, `lazy`, `sleep`]))
} catch {
console.log(`Oh no! It had more than one value...`)
}
//=> Oh no! It had more than one value...
Since
v0.0.1