Last active
May 3, 2017 16:04
-
-
Save rvcas/091d039099b248270f3ef52e59f500e6 to your computer and use it in GitHub Desktop.
Some nonsense in Elm
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
running
elm-reactor
in the directory containing this file should be enough to run it