on master help sign in
Revert "Implement "min", "max", and "clamp" in Elm"

This reverts commit f098af57cc7551cb57ccbbc122d80b4f90ad5b03. Conflicts: libraries/Native/Basics.js

commit5bc4e26b9d4de02cd0fe4a1a7b67fe278dc0345a authorEvan Czaplicki <info@elm-lang.org> dateFri 22 Aug 2014, 23:59 (12 years ago) parent0d3cba6
2 files changed+17−6
libraries/Basics.elm+3−6 libraries/Native/Basics.js+14
libraries/Basics.elm+3−6
@@ -181,10 +181,7 @@ logBase = Native.Basics.logBase
181181 200 if 200 <= x
182182-}
183183clamp : number -> number -> number -> number
184−clamp lo hi n =
185− if | n < lo -> lo
186− | n > hi -> hi
187− | otherwise -> n
184+clamp = Native.Basics.clamp
188185
189186{-| An approximation of pi. -}
190187pi : Float
@@ -233,11 +230,11 @@ data Order = LT | EQ | GT
233230
234231{-| Given two comparables, returns the smaller one. -}
235232min : comparable -> comparable -> comparable
236−min a b = if a < b then a else b
233+min = Native.Basics.min
237234
238235{-| Given two comparables, returns the larger one. -}
239236max : comparable -> comparable -> comparable
240−max a b = if a > b then a else b
237+max = Native.Basics.max
241238
242239{-| The and operator. True if both inputs are True.
243240This operator short-circuits if the first argument is False.
libraries/Native/Basics.js+14
@@ -18,6 +18,17 @@ Elm.Native.Basics.make = function(elm) {
1818 function logBase(base, n) {
1919 return Math.log(n) / Math.log(base);
2020 }
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+
2132 function xor(a, b) {
2233 return a !== b;
2334 }
@@ -71,6 +82,9 @@ Elm.Native.Basics.make = function(elm) {
7182
7283 sqrt: Math.sqrt,
7384 logBase: F2(logBase),
85+ min: F2(min),
86+ max: F2(max),
87+ clamp: F3(clamp),
7488 compare: Utils.compare,
7589
7690 xor: F2(xor),