Created
August 11, 2017 14:36
-
-
Save zgohr/7e42c38c99e9ad68a13721ad787bf130 to your computer and use it in GitHub Desktop.
Elm simplification questions from Slack
This file contains 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
queryfn = | |
let | |
elementMaybe = | |
Array.get index theQuery.selectlinescontainer | |
element = | |
case elementMaybe of | |
Just el -> | |
el | |
Nothing -> | |
xSelectLine | |
newElement = | |
{ element | equation = input } | |
newContainer = | |
Array.set index newElement theQuery.selectlinescontainer | |
newQueryEl = | |
{ theQuery | selectlinescontainer = newContainer } | |
index = | |
theQuery.queryId | |
beforePart = | |
if (index > 0) then | |
List.take index model.queries | |
else | |
[] | |
afterPart = | |
List.drop (index + 1) model.queries | |
in | |
{ model | queries = beforePart ++ [ newQueryEl ] ++ afterPart } ! [] | |
-- The first 7 lines, for example, could be this: `element = Array.get index theQuery.selectlinescontainer |> Maybe.withDefault xSelectLine` | |
-- The next few could be `newQueryEl = { theQuery | selectlinescontainer = Array.set theQuery.queryId { element | equation = input } theQuery.selectlinescontainer }` | |
-- and the next bit could be `queries = List.indexedMap (\idx -> if idx == theQuery.queryId then (always newQueryEl) else identity) model.queries` | |
-- now, with those in hand, you could look into spltting some of that off into helper functions, gradually moving your logic out of your `update` until it just dispatches functions, that call helpers to do their thing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment