extract<T> method

Option<T> extract<T>(
  1. K key
)

Return an Option that conditionally accesses map keys, if they match the given type. Useful for accessing nested JSON.

expect(
  some({ 'test': 123 }).extract<int>('test'),
  some(123),
);

Implementation

Option<T> extract<T>(K key) => chain(flatMap((map) => map.extract(key)));