From f3c097b4a826ff1e5c050731eb76c3eb3de5cdd6 Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Thu, 29 Jul 2021 15:42:26 +0200 Subject: [PATCH 1/2] fix #26 --- Project.toml | 1 + src/functionlenses.jl | 4 ++++ src/staticarrays.jl | 7 ++----- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 99c0a01c..a98e3c0d 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" CompositionsBase = "a33af91c-f02d-484b-be07-31d278c5ca2b" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" Future = "9fa8497b-333b-5362-9e8d-4d0656e87820" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/functionlenses.jl b/src/functionlenses.jl index 874704eb..ec4243cb 100644 --- a/src/functionlenses.jl +++ b/src/functionlenses.jl @@ -1,3 +1,4 @@ +using LinearAlgebra: norm, normalize set(obj, ::typeof(last), val) = @set obj[lastindex(obj)] = val set(obj, ::typeof(first), val) = @set obj[firstindex(obj)] = val set(obj, ::typeof(identity), val) = val @@ -34,3 +35,6 @@ set(path, ::typeof(basename), new_name) = @set splitdir(path)[2] = new_na set(x::Real, ::typeof(real), y) = y set(x, ::typeof(real), y) = y + im*imag(x) set(x, ::typeof(imag), y) = real(x) + im*y + +set(arr, ::typeof(normalize), val) = norm(arr) * val +set(arr, ::typeof(norm), val) = val/norm(arr) * arr # shoud we check val is positive? diff --git a/src/staticarrays.jl b/src/staticarrays.jl index 2cc29f4b..93efbcd6 100644 --- a/src/staticarrays.jl +++ b/src/staticarrays.jl @@ -1,5 +1,2 @@ -import StaticArrays; const SA = StaticArrays -setindex(a::SA.StaticArray, args...) = Base.setindex(a, args...) - -set(arr, ::typeof(SA.normalize), val) = SA.norm(arr) * val -set(arr, ::typeof(SA.norm), val) = val/SA.norm(arr) * arr # shoud we check val is positive? +import .StaticArrays +Accessors.setindex(a::StaticArrays.StaticArray, args...) = Base.setindex(a, args...) From 47013d88532f3d1aba3e7904a295b3ab820af8cd Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Thu, 29 Jul 2021 15:49:02 +0200 Subject: [PATCH 2/2] v0.1.4 --- Project.toml | 2 +- src/functionlenses.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index a98e3c0d..58b05c04 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Accessors" uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" authors = ["Takafumi Arakaki ", "Jan Weidner and contributors"] -version = "0.1.3" +version = "0.1.4" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/functionlenses.jl b/src/functionlenses.jl index ec4243cb..1b163016 100644 --- a/src/functionlenses.jl +++ b/src/functionlenses.jl @@ -37,4 +37,4 @@ set(x, ::typeof(real), y) = y + im*imag(x) set(x, ::typeof(imag), y) = real(x) + im*y set(arr, ::typeof(normalize), val) = norm(arr) * val -set(arr, ::typeof(norm), val) = val/norm(arr) * arr # shoud we check val is positive? +set(arr, ::typeof(norm), val) = val/norm(arr) * arr # should we check val is positive?