Skip to content

Instantly share code, notes, and snippets.

View teivah's full-sized avatar
Building my newsletter: The Coder Cafe

Teiva Harsanyi teivah

Building my newsletter: The Coder Cafe
View GitHub Profile
fmapEx :: Maybe Int
fmapEx = fmap (+ 1) Nothing -- Nothing
fmapEx :: Maybe Int -- A function returning a Maybe Int
fmapEx = fmap (+ 1) (Just 42) -- Just 43
applicativeEx :: Maybe Int
applicativeEx = (+ 1) <$> Just 42 -- Just 43
applicativeEx :: [Int]
applicativeEx = [(+ 1)] <*> [1, 2, 3] -- [2, 3, 4]
applicativeEx :: Maybe Int
applicativeEx = Just (+ 1) <*> Just 42 -- Just 43
applicativeEx :: Maybe Int
applicativeEx = Just (+ 1) <*> Just 42 -- Just 43
@teivah
teivah / fmap.hs
Last active March 16, 2024 01:12
fmapEx :: [Int] -- A function returning a list
fmapEx = fmap (+ 1) [1, 2, 3] -- [2, 3, 4]
@teivah
teivah / fmap.hs
Last active March 16, 2024 00:43
fmapEx :: Maybe Int
fmapEx = fmap (Just (+ 1)) (Just 42) -- Does not compile
@teivah
teivah / fmap.hs
Last active March 16, 2024 00:34
fmapEx :: Maybe Int
fmapEx = fmap (+ 1) Nothing -- Nothing
@teivah
teivah / fmap.hs
Last active March 16, 2024 01:13
fmapEx :: Maybe Int -- A function returning a Maybe Int
fmapEx = fmap (+ 1) (Just 42) -- Nothing