import Slides
slidesDefaultConfig =
Slides.defaultConfig
myCustomSlidesConfig =
{ slidesDefaultConfig | someAttribute = myCustomvalue }import Slides exposing (slidesDefaultConfig)
myCustomSlidesConfig =
{ slidesDefaultConfig | someAttribute = myCustomvalue }Re-posting the first example from Franscisco's thread:
Can we express these in terms of examples of real-world code that is currently painful? That's really the key here. :)
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/oWfARte8DJU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
type alias Model =
{ cards : List Card }
type alias Card =
{ content : String
, imageSrc : Msg
, likes : Int
, style : Animation.State
} Animate time ->
let
updateCard card =
{ card | style = Animation.update time card.style }
in
( { model
| cards =
List.map updateCard model.cards
}
, Cmd.none
)
Animate time ->
let
updateCard card (updatedCards,cmd) =
let
(newStyle, newCmd) = Animation.Messenger.update time card.style
newCard = { card | style = newStyle }
in
( updatedCards ++ [ newCard ]
, Cmd.batch [ newCmd, cmd ]
)
(updatedCards, cmds) =
List.foldl
updateCard
([], Cmd.none)
model.cards
in
( { model | cards = updatedCards }
, cmds
)
decodeModel : Json.Value -> Result String Model
decodeModel value =
Ok { name = "", age = 0 }
|> decodeField "age" Json.int setAge value
|> decodeField "name" Json.string setName value
setName : Model -> String -> Model
setName model name =
{ model | name = name }
update : Msg -> Model -> ( Model, Cmd Msg )update action model = case action of Refresh -> model ! [ Cmd.map VersionMsg Version.loadVersion , Cmd.map HealthMsg Health.loadHealth , Cmd.map ServicesMsg Services.loadServices ]
ServicesMsg sub -> let ( services, cmd ) = Services.update sub model.services in { model | services = services } ! [ Cmd.map ServicesMsg cmd ]
VersionMsg sub -> let ( version, cmd ) = Version.update sub model.version in { model | version = version } ! [ Cmd.map VersionMsg cmd ]
HealthMsg sub -> let ( health, cmd ) = Health.update sub model.health in { model | health = health } ! [ Cmd.map HealthMsg cmd ]--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
case model.route of Routes.Entry { mode } -> if mode == Read then (hex "FFFFFF") else (hex "f6f6f6")
_ -> (hex "f6f6f6")case model.route of Routes.Entry { mode = Read } -> hex "ffffff" _ -> hex "f6f6f6"let default = hex "f6f6f6"in case model.route of Routes.Entry { mode } -> if mode == Read then (hex "FFFFFF") else default
_ -> defaultOur codebase suffers from this as well.
( { model | mode =
case model.mode of
Drawing maybe ->
case maybe of
Just shape ->
Drawing <| Just <| Shapes.setID id shape
_ ->
model.mode
_ ->
model.mode
}
, Cmd.none
)( { model | mode =
case model.mode of
Drawing (Just shape) ->
Drawing <| Just <| Shapes.setID id shape
_ ->
model.mode
}
, Cmd.none
)let
newMode =
case model.mode of
Drawing (Just shape) ->
Drawing <| Just <| Shapes.setID id shape
_ ->
model.mode
in
( { model | mode = newMode }
, Cmd.none
)
type alias RuleContentAnd a =
{ a
| category : Category
, name : String
, template : Template
, view : View
, arguments : List Argument
}
type alias RuleContent =
RuleContentAnd {}
type alias Rule =
RuleContentAnd { id : Id }
ruleToRuleContent : Rule -> RuleContent
ruleToRuleContent rule =
{ arguments = rule.arguments
, name = rule.name
, template = rule.template
, view = rule.view
, category = rule.category
}
ruleToRuleContent : Rule -> RuleContent
ruleToRuleContent rule =
removeAttribute .id rule
-- Family.elm
updateFamily msg family =
case msg of
ChangeName newName -> ( { family | name = newName }, Cmd.none )
Save -> ( model, saveFamily family )
selectedView family =
UI.form
[ UI.class "fluid"
, UI.onSubmit <| SaveFamily model.family
]
[ UI.input
[ UI.label "Name"
, UI.value model.family.name
, UI.onInput ChangeName
]
]
-- Update.elm
update msg model =
case msg of
FamilyMsg familyMsg ->
let
(newFamily, familyCmd) = Family.update familyMsg model.family
in
( { model | family = newFamily }, Cmd.map FamilyMsg familyCmd )
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
case lol of
Submit locationList ->
let
results =
validateEditLocationListForm model.locationListData
( newLocationListData, cmd ) =
if List.length results > 0 then
( { locationListData | errors = Just results }, Cmd.none )
else
( { model | locationListData = data }, postUpdateLocationList locationListData locationList )
in
( { model | locationListData = newLocationListData }, cmd )
My use case is my data is modeled in a “has a” kind of way. I have rounds and I have lightning talks. A round has a date, it has a theme, and a round also has a collection of lightning talks. I am very often writing boilerplate for updating the nested lightning talk models because the primary domain object I’m usually dealing with is a round.
Here's a simplified snippet of code.
type alias LightningTalk =
{ title : String
, description : String }
type alias Round =
{ talk1 : LightningTalk
, theme : String
, date : Float }
update msg model =
case msg of
UpdateTalkTitle newTitle ->
let
talk1 =
model.talk1
nextTalk =
{ talk1 | title = newTitle }
in
{ model | talk1 = nextTalk }
I think there's room to reduce boilerplate in the highlighted code as well as make it more beginner friendly, since it's not obvious to store temporary results in temporary variables like talk1 or nextTalk.
@field :{ get : { a | field : b } -> b, set : b -> { a | field : b } -> { a | field : b }
}@field ={ get = \r -> r.field, set = \v r -> { r | field = v }}
streetNameOfAddress : Lens Address StringstreetNameOfAddress =letget a = a.streetNameset sn a = { a | streetName = sn }inLens get set
streetNameOfAddress : Lens Address StringstreetNameOfAddress =Lens @streetName
update msg model =case msg of
SearchPage msg_ ->let(searchPage_, cmd) = SearchPage.update msg_ model.searchPagein( { model | searchPage = searchPage_ }, cmd )
update msg model =case msg of
SearchPage msg_ ->Compose.update msg_ model @searchPage SearchPage.update
{ get = .searchPage, set = \v r -> { r | searchPage = v } }
module At exposing (field, name, searchPage)field = { get = .field, set = \v r -> { r | field = v } }name = { get = .name, set = \v r -> { r | name = v } }searchPage = { get = .searchPage, set = \v r -> { r | searchPage = v } }
type alias Model = { home : Home.Model , about : About.Model }
type Msg = HomeMsg Home.Msg | AboutMsg About.Msg
update : Msg -> Model -> ( Model, Cmd Msg )update msg model = case msg of HomeMsg msg_ -> let ( page, cmd ) = Home.update msg_ model.home in ( { model | home = page }, Cmd.map HomeMsg cmd )lift : (msg -> Msg) -> (Model -> a -> Model) (a, Cmd msg) -> (Model, Cmd Msg)lift cmdMapper modelMapper (m, c) = ( (modelMapper m), (Cmd.map cmdMapper c) )
setHome : Model -> a -> ModelsetHome model page = { model | home = page }lift HomeMsg (setHome model) <| Home.update msg_ model.home context
type Rect = { left : Int, top : Int, right : Int, bottom : Int }type Style = { padding : Rect, ... }
{ style | padding = { style.padding | left = 10 } }
letoldPadding =style.paddingnewPadding ={ oldPadding | left = 10 }in{ style | padding = newPadding }
10 |> asLeftIn style.padding |> asPaddingIn style
But rather have to write:{ Style.default | color = "red" }
defaultStyle : Style.StyledefaultStyle = Style.default...{ defaultStyle | color = "red" }
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
# type t = { a : int ; b : float } ;;
type t = { a : int; b : float; }
# let emptyT () = { a = 1 ; b = 3.0 } ;;
val emptyT : unit -> t = <fun>
# let x = { (emptyT ()) with a = 7 } ;;
val x : t = {a = 7; b = 3.}
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
type alias Model = { paras : Dict Int Para , selection : Maybe Selection } type alias Para = { text : String } type alias Selection = { cursorCoordinate : TextCoordinate , anchorCoordinate : TextCoordinate -- not in use yet } type alias TextCoordinate = { textPos : TextPosition , location : Location } type alias TextPosition = { iPara : Int , offset : Int } type Location = Before | Afterdismantle : TextCoordinate -> ( Int, Int, Location )dismantle tc = ( tc.textPos.offset, tc.textPos.iPara, tc.location )
moveLeft : Model -> TextCoordinate -> Maybe SelectionmoveLeft model ({ textPos } as cursorCoordinate) = let ( offsetCur, iParaCur, locationCur ) = dismantle cursorCoordinate
paraCur = Dict.get iParaCur model.paras
cursorCoordinateNew = case paraCur of Nothing -> -- this should never happen, since we should have a valid text coordinate at that point cursorCoordinate
Just para -> let paraLength = String.length para.text
iParaAbove = iParaCur - 1
offsetNew = (offsetCur - 1) |> cropTo -1 (paraLength - 1) in if (offsetNew < 0) then if (paraLength > 0 && locationCur == After) then -- we moved "after -1st" character: normalize to "before 0st" textPos |> setOffset 0 |> asTextPosIn cursorCoordinate |> setLocation Before else -- we moved "before -1st" character or we are in an empty para: -- => normalize to "after last of prev. para" let mbParaAbove = Dict.get iParaAbove model.paras in case mbParaAbove of Nothing -> textPos |> setOffset 0 |> setIPara 0 |> asTextPosIn cursorCoordinate |> setLocation Before
Just paraAbove -> let paraAboveLength = String.length paraAbove.text
offsetAbove = paraAboveLength |> cropTo 0 paraAboveLength in textPos |> setOffset offsetAbove |> setIPara iParaAbove |> asTextPosIn cursorCoordinate |> setLocation After else textPos |> setOffset offsetNew |> asTextPosIn cursorCoordinate in createSelection cursorCoordinateNewsetSelection : Maybe Selection -> Model -> ModelsetSelection selectionNew modelCur = { modelCur | selection = selectionNew }
asSelectionIn : Model -> Maybe Selection -> ModelasSelectionIn = flip setSelection
setParas : Dict Int Para -> Model -> ModelsetParas parasNew modelCur = { modelCur | paras = parasNew }
asParasIn : Model -> Dict Int Para -> ModelasParasIn = flip setParas setText : String -> Para -> ParasetText textNew paraCur = { paraCur | text = textNew }
asTextIn : Para -> String -> ParaasTextIn = flip setText
setCursorCoordinate : TextCoordinate -> Selection -> SelectionsetCursorCoordinate cursorCoordinateNew selectionCur = { selectionCur | cursorCoordinate = cursorCoordinateNew }
asCursorCoordinateIn : Selection -> TextCoordinate -> SelectionasCursorCoordinateIn = flip setCursorCoordinate
setAnchorCoordinate : TextCoordinate -> Selection -> SelectionsetAnchorCoordinate anchorCoordinateNew selectionCur = { selectionCur | anchorCoordinate = anchorCoordinateNew }
asAnchorCoordinateIn : Selection -> TextCoordinate -> SelectionasAnchorCoordinateIn = flip setAnchorCoordinate setTextPos : TextPosition -> TextCoordinate -> TextCoordinatesetTextPos textPosNew textCoordinateCur = { textCoordinateCur | textPos = textPosNew }
asTextPosIn : TextCoordinate -> TextPosition -> TextCoordinateasTextPosIn = flip setTextPos
setLocation : Location -> TextCoordinate -> TextCoordinatesetLocation locationNew textCoordinateCur = { textCoordinateCur | location = locationNew }
asLocationIn : TextCoordinate -> Location -> TextCoordinateasLocationIn = flip setLocation
setIPara : Int -> TextPosition -> TextPositionsetIPara iParaNew textPosCur = { textPosCur | iPara = iParaNew }
asIParaIn : TextPosition -> Int -> TextPositionasIParaIn = flip setIPara
setOffset : Int -> TextPosition -> TextPositionsetOffset offsetNew textPosCur = { textPosCur | offset = offsetNew }
asOffsetIn : TextPosition -> Int -> TextPositionasOffsetIn = flip setOffsetsetImage : String -> String -> Image -> Model -> Model
setImage tool url image model =
let
mapping =
case tool of
"rectangle" ->
.rectangle model.resourcesMapping
"outline" ->
.outline model.resourcesMapping
"scribbles" ->
.scribbles model.resourcesMapping
_ ->
Dict.empty
id =
Dict.get url mapping
|> Maybe.withDefault -1
config =
model.config
newConfig =
case tool of
"rectangle" ->
{ config | rectangle = Dict.insert id (NoGT url image) config.rectangle }
"outline" ->
{ config | outline = Dict.insert id (NoGT url image) config.outline }
"scribbles" ->
{ config | scribbles = Dict.insert id (NoGT url image) config.scribbles }
_ ->
config
in
{ model | config = newConfig }
canvasPosition : Model -> Position
canvasPosition model =
let
pos =
model.mousePosition
in
{ pos | y = pos.y - headerHeight }
type alias Note =
{ position : Int
, note : Int
, velocity : Int
, length : Int
}
type alias Detailed a =
{ a | track : Int, channel : Int }
addDetails : Int -> Int -> Note -> Detailed Note
addDetails track channel note =
{ position = note.position
, note = note.note
, velocity = note.velocity
, length = note.length
, channel = channel
, track = track
}