path overview
Added in v0.0.5
Table of contents
object
path
Retrieve the value at a given path.
Signature
export declare const path: (pth: string) => <A>(a: Record<string, A>) => O.Option<A>
Example
import { path } from '@warungpintar/ninshu'
const data = {
name: {
firstname: 'john',
lastname: 'doe',
},
age: 40,
}
const takeFirstName = path('name.firstname')
const takeLastName = path('name.lastname')
const takeHobbies = path('hobbies')
takeFirstName(data)
// Some("john")
takeLastName(data)
// Some("doe");
takeHobbies(data)
// None
Added in v0.0.5