Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
import Graphics.Element exposing (Element)
import Graphics.Collage exposing (..)
import Color
import Signal
import Time
-- Play with this value and hot swap the code
gravity = -9.8
--
import Html exposing (Html)
import Signal exposing (Address)
type alias Vector =
{ x : Float , y : Float }
----------------------------------
type alias Init options state effect = options -> (state, effect)
type alias Update action state effect = action -> state -> (state, effect)
type alias Update action state = action -> state -> state
type alias View action state = Address action -> state -> Html
type alias Init options state = Vector -> options -> state
@TheSeamau5
TheSeamau5 / updateN.elm
Created July 20, 2015 16:26
UpdateN function
updateN : Int -> (a -> a) -> List a -> List a
updateN n f list =
List.indexedMap (\index value -> if index == n then f value else value) list

Type signatures for elm-html components (without effects)

First, consider the following type aliases

type alias Init options state = options -> state
-- type alias Init option state = Vector -> options -> state
-- alternative version if using inline styles

type alias Update action state = action -> state -> state
import Graphics.Element exposing (show)
type Mappable a b ma mb = Mappable
{ map : (a -> b) -> ma -> mb }
map : (a -> b) -> ma -> { ext | mappable : Mappable a b ma mb } -> mb
map f m {mappable} = case mappable of
Mappable {map} -> map f m
@TheSeamau5
TheSeamau5 / ScrollList.elm
Last active August 29, 2015 14:25
Scroll List in Elm
import Html exposing (Html, Attribute)
import Html.Attributes
import Html.Events
import Json.Decode exposing (Decoder, (:=))
import List
import Signal exposing (Address)
import StartApp
import Array exposing (Array)
import Window
@TheSeamau5
TheSeamau5 / monadicsprings.elm
Created July 10, 2015 20:58
Monadic springs
import Html exposing (Html)
import Html.Attributes
import Time
import Mouse
import Signal
-----------
infixl 2 =>
(=>) = (,)
@TheSeamau5
TheSeamau5 / mappablespringanimations.elm
Last active December 15, 2015 19:42
Mappable Spring Animations
import Html exposing (Html)
import Html.Attributes
import Time
import Mouse
import Signal
-----------
infixl 2 =>
(=>) = (,)
type alias Spring a =
{ stiffness : Float
, friction : Float
, position : a
, velocity : a
, destination : a
}