Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // findByIndex :: Int -> [a] -> Maybe a
- // 0 1 2
- const arr = [2, 4, 6]
- const testJust = findByIndex (2) (arr)
- // => { val = 2 }
- const testNothing = findByIndex (3) (arr)
- // => { val = null }
- // mapMaybe :: (a -> b) -> Maybe a -> Maybe b
- const succ = x => x + 1
- mapMaybe (succ) (testJust)
- // => { val = 3 }
- mapMaybe (succ) (testNothing)
- // => { val = null }
- // isJust :: Maybe a -> Bool
- isJust (testJust)
- // => true
- isJust (testNothing)
- // => false
- // fromJust :: Maybe a -> a
- fromJust (testJust)
- // => 2
- fromJust (testNothing)
- // => ОШИБКА!
- // withDefault :: a -> Maybe a -> a
- withDefault (0) (testJust)
- // => 2
- withDefault (0) (testNothing)
- // => 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement