Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (..)
- import Html
- type Maybe a
- = Just a
- | Nothing
- mapMaybe : (a -> b) -> Maybe a -> Maybe b
- mapMaybe f perhaps =
- case perhaps of
- Nothing ->
- Nothing
- Just a ->
- Just (f a)
- maybeToList : (a -> b) -> List (Maybe a) -> List b
- maybeToList f perhaps =
- case perhaps of
- x :: xs ->
- let
- result =
- mapMaybe f x
- in
- case result of
- Nothing ->
- maybeToList f xs
- Just a ->
- a :: maybeToList f xs
- [] ->
- []
- main : Html.Html a
- main =
- Html.text <|
- case test of
- [ 2, 4 ] ->
- "pass"
- _ ->
- "fail"
- succ : Int -> Int
- succ =
- (+) 1
- test : List Int
- test =
- let
- maybe_list =
- [ Just 1, Nothing, Just 3, Nothing ]
- in
- maybeToList succ maybe_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement