elm-mdl/src/Material/Helpers.elm

38 lines
764 B
Elm
Raw Normal View History

module Material.Helpers where
2016-03-08 17:30:09 +01:00
import Html
import Html.Attributes
import Effects exposing (Effects)
filter : (a -> List b -> c) -> a -> List (Maybe b) -> c
filter elem attr html =
elem attr (List.filterMap (\x -> x) html)
2016-03-13 22:47:00 +01:00
mapWithIndex : (Int -> a -> b) -> List a -> List b
mapWithIndex f xs =
let
loop k ys =
case ys of
[] -> []
y :: ys -> f k y :: loop (k+1) ys
in
loop 0 xs
2016-03-08 17:30:09 +01:00
effect : Effects b -> a -> (a, Effects b)
effect e x = (x, e)
pure : a -> (a, Effects b)
pure = effect Effects.none
clip : comparable -> comparable -> comparable -> comparable
clip lower upper k = Basics.max lower (Basics.min k upper)
blurOn : String -> Html.Attribute
blurOn evt =
Html.Attributes.attribute ("on" ++ evt) <| "this.blur()"