Created
May 7, 2017 15:26
-
-
Save anonymous/ba9ee6d11867731db5d2ce614d829260 to your computer and use it in GitHub Desktop.
takeWhileMap
This file contains hidden or 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
{ | |
"version": "1.0.0", | |
"summary": "provides takeWhileMap, function is executed only while it returns Just smth, first Nothing stops the execution", | |
"repository": "https://github.com/user/project.git", | |
"license": "BSD3", | |
"source-directories": [ | |
"." | |
], | |
"exposed-modules": [], | |
"dependencies": { | |
"elm-lang/core": "5.1.1 <= v < 5.1.1", | |
"elm-lang/html": "2.0.0 <= v < 2.0.0" | |
}, | |
"elm-version": "0.18.0 <= v < 0.19.0" | |
} |
This file contains hidden or 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
<html> | |
<head> | |
<style> | |
html { | |
background: #F7F7F7; | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var app = Elm.Main.fullscreen() | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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 exposing (Html, text) | |
import List exposing (..) | |
takeWhileMap : (a -> Maybe b) -> List a -> List b | |
takeWhileMap f src = | |
Tuple.second | |
(List.foldl | |
(\item acc -> | |
case acc of | |
( True, res ) -> | |
case (f item) of | |
Just val -> ( True, res ++ [ val ] ) | |
Nothing -> ( False, res ) | |
( False, res ) -> acc) | |
( True, [] ) | |
src) | |
main : Html a | |
main = | |
text | |
(toString | |
(takeWhileMap | |
(\n -> if (n <= 3) then Just (n - 10) else Nothing) | |
[ 2, 1, 0, 1, 3, 5, 1, 0, 2, 3 ]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment