Last active
July 29, 2018 18:22
-
-
Save joneshf/b99f5f1f3ea56019e719e5ba2ef2e58d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Control.Monad.Eff.Console (logShow) | |
import Data.Bifunctor (lmap) | |
import Data.Maybe (Maybe(Just, Nothing)) | |
import Data.Tuple (Tuple(Tuple)) | |
import Data.Unfoldable (class Unfoldable, unfoldr) | |
import TryPureScript (render, withConsole) | |
unfoldr' :: | |
forall a b f. | |
Unfoldable f => | |
(b -> Maybe (Tuple a b)) -> | |
b -> | |
f (Tuple a b) | |
unfoldr' f = unfoldr (\x -> map (lmap (flip Tuple x)) (f x)) | |
-- | A Name consists of a first name and a last name | |
inc :: Int -> Maybe (Tuple String Int) | |
inc x | |
| x > 5 = Nothing | |
| otherwise = Just (Tuple ("val: " <> show x) (x + 1)) | |
main = render =<< withConsole do | |
logShow (unfoldr inc 0 :: Array String) | |
logShow (unfoldr' inc 0 :: Array (Tuple String Int)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment