diff --git a/elm-package.json b/elm-package.json index 1633376..5951381 100644 --- a/elm-package.json +++ b/elm-package.json @@ -1,6 +1,6 @@ { - "version": "2.0.0", - "summary": "an experimental library for easily updating nested records", + "version": "2.0.1", + "summary": "an experimental library for working with records", "repository": "https://github.com/evancz/focus.git", "license": "BSD3", "source-directories": [ @@ -10,7 +10,8 @@ "Focus" ], "dependencies": { - "elm-lang/core": "2.0.0 <= v < 4.0.0" + "elm-lang/core": "4.0.0 <= v < 5.0.0", + "elm-lang/html": "1.0.0 <= v < 2.0.0" }, - "elm-version": "0.15.0 <= v < 0.17.0" + "elm-version": "0.17.0 <= v < 0.18.0" } \ No newline at end of file diff --git a/examples/Physics.elm b/examples/Physics.elm new file mode 100644 index 0000000..c0aef54 --- /dev/null +++ b/examples/Physics.elm @@ -0,0 +1,63 @@ +import Focus exposing (..) +import Html exposing (..) + + + +-- OBJECTS + + +type alias Object = + { position : Point + , velocity : Point + } + + +type alias Point = + { x : Float + , y : Float + } + + + +-- DO STUFF + + +main : Html msg +main = + text (toString (step 1.5 object)) + + +object : Object +object = + Object (Point 3 4) (Point 1 1) + + +step : Float -> Object -> Object +step dt object = + object + |> update (position => x) (\px -> px + object.velocity.x * dt) + |> update (position => y) (\py -> py + object.velocity.y * dt) + + + +-- FOCI + + +x : Focus { r | x:a } a +x = + create .x (\f r -> { r | x = f r.x }) + + +y : Focus { r | y:a } a +y = + create .y (\f r -> { r | y = f r.y }) + + +position : Focus { r | position : a } a +position = + create .position (\f r -> { r | position = f r.position }) + + +velocity : Focus { r | velocity : a } a +velocity = + create .velocity (\f r -> { r | velocity = f r.velocity }) diff --git a/examples/elm-package.json b/examples/elm-package.json deleted file mode 100644 index 2b422d5..0000000 --- a/examples/elm-package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Focus examples (for 0.16.x)", - "repository": "https://github.com/evancz/focus.git", - "license": "BSD3", - "source-directories": [ - "src" - ], - "exposed-modules": [ - ], - "dependencies": { - "elm-lang/core": "3.0.0 <= v < 4.0.0" - }, - "elm-version": "0.16.0 <= v < 0.17.0" -} diff --git a/examples/src/Physics.elm b/examples/src/Physics.elm deleted file mode 100644 index 8c58ec4..0000000 --- a/examples/src/Physics.elm +++ /dev/null @@ -1,43 +0,0 @@ -import Focus (..) - -type Point = - { x : Float - , y : Float - } - -type Object = - { position : Point - , velocity : Point - } - -object : Object -object = - { position = { x=3, y=4 } - , velocity = { x=1, y=1 } - } - -physics : Float -> Object -> Object -physics dt object = - object - |> update (position => x) (\px -> px + object.velocity.x * dt) - |> update (position => y) (\py -> py + object.velocity.y * dt) - -main : Element -main = asText (physics 1 object) - - --- Create all of the Foci - -x : Focus { r | x:a } a -x = create .x (\f r -> { r | x = f r.x }) - -y : Focus { r | y:a } a -y = create .y (\f r -> { r | y = f r.y }) - -position : Focus { r | position:a } a -position = - create .position (\f r -> { r | position = f r.position }) - -velocity : Focus { r | velocity:a } a -velocity = - create .velocity (\f r -> { r | velocity = f r.velocity }) diff --git a/src/Focus.elm b/src/Focus.elm index 9802993..30aa99d 100644 --- a/src/Focus.elm +++ b/src/Focus.elm @@ -1,4 +1,4 @@ -module Focus (Focus, get, set, update, (=>), create) where +module Focus exposing (Focus, get, set, update, (=>), create) {-| Our goal is to update a field deep inside some nested records. For example, if we want to add one to `object.physics.velocity.x` or set it to zero, we would be writing code like this: