Search


Search something to see results

flatMap

Type Parameters

  • Input
  • Output

Parameters

  • mapper: Object
  • Optionalname: string

Returns Object

import * as x from 'unhoax'

const mapNumberFromString = x.flatMap((value: string) => x.number.parse(Number(value)))
const numberFromString = mapNumberFromString(string)

numberFromString.parse('12') // { success: true, value: 12 }

// or, using pipe
import pipe from 'just-pipe'

const numberFromString = pipe(
x.string,
x.map(Number),
x.flatMap(x.number.parse),
)