on master help sign in
Revert "Implement "min", "max", and "clamp" in Elm"
5bc4e26Evan Czaplicki
libraries/Basics.elm+3−6
@@ -181,10 +181,7 @@ logBase = Native.Basics.logBase
181 200 if 200 <= x
181 200 if 200 <= x
182-}
182-}
183clamp : number -> number -> number -> number
183clamp : number -> number -> number -> number
184−clamp lo hi n =
184+clamp = Native.Basics.clamp
185− if | n < lo -> lo
186− | n > hi -> hi
187− | otherwise -> n
188
185
189{-| An approximation of pi. -}
186{-| An approximation of pi. -}
190pi : Float
187pi : Float
@@ -233,11 +230,11 @@ data Order = LT | EQ | GT
233
230
234{-| Given two comparables, returns the smaller one. -}
231{-| Given two comparables, returns the smaller one. -}
235min : comparable -> comparable -> comparable
232min : comparable -> comparable -> comparable
236−min a b = if a < b then a else b
233+min = Native.Basics.min
237
234
238{-| Given two comparables, returns the larger one. -}
235{-| Given two comparables, returns the larger one. -}
239max : comparable -> comparable -> comparable
236max : comparable -> comparable -> comparable
240−max a b = if a > b then a else b
237+max = Native.Basics.max
241
238
242{-| The and operator. True if both inputs are True.
239{-| The and operator. True if both inputs are True.
243This operator short-circuits if the first argument is False.
240This operator short-circuits if the first argument is False.
libraries/Native/Basics.js+14
@@ -18,6 +18,17 @@ Elm.Native.Basics.make = function(elm) {
18 function logBase(base, n) {
18 function logBase(base, n) {
19 return Math.log(n) / Math.log(base);
19 return Math.log(n) / Math.log(base);
20 }
20 }
21+
22+ function min(a, b) {
23+ return Utils.cmp(a,b) < 0 ? a : b;
24+ }
25+ function max(a, b) {
26+ return Utils.cmp(a,b) > 0 ? a : b;
27+ }
28+ function clamp(lo, hi, n) {
29+ return Utils.cmp(n,lo) < 0 ? lo : Utils.cmp(n,hi) > 0 ? hi : n;
30+ }
31+
21 function xor(a, b) {
32 function xor(a, b) {
22 return a !== b;
33 return a !== b;
23 }
34 }
@@ -71,6 +82,9 @@ Elm.Native.Basics.make = function(elm) {
71
82
72 sqrt: Math.sqrt,
83 sqrt: Math.sqrt,
73 logBase: F2(logBase),
84 logBase: F2(logBase),
85+ min: F2(min),
86+ max: F2(max),
87+ clamp: F3(clamp),
74 compare: Utils.compare,
88 compare: Utils.compare,
75
89
76 xor: F2(xor),
90 xor: F2(xor),