2016-03-16 05:32:41 +00:00
|
|
|
module Material.Helpers where
|
2016-03-08 16:30:09 +00: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 21:47:00 +00: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 16:30:09 +00:00
|
|
|
effect : Effects b -> a -> (a, Effects b)
|
|
|
|
effect e x = (x, e)
|
|
|
|
|
|
|
|
|
|
|
|
pure : a -> (a, Effects b)
|
|
|
|
pure = effect Effects.none
|
|
|
|
|
|
|
|
|
2016-03-17 12:31:43 +00:00
|
|
|
addFx : Effects a -> (model, Effects a) -> (model, Effects a)
|
|
|
|
addFx effect1 (model, effect2) =
|
|
|
|
(model, Effects.batch [effect1, effect2])
|
|
|
|
|
|
|
|
mapFx : (a -> b) -> (model, Effects a) -> (model, Effects b)
|
|
|
|
mapFx f (model, effect) =
|
|
|
|
(model, Effects.map f effect)
|
|
|
|
|
2016-03-08 16:30:09 +00:00
|
|
|
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()"
|