@@ -4,7 +4,6 @@ module Basics.Extra exposing
44 , safeModBy, safeRemainderBy
55 , inDegrees, inRadians, inTurns
66 , flip, curry, uncurry
7- , swap, atMost, atLeast, fractionalModBy, orderBy, toOrder, toOrderDesc
87 )
98
109{- | Additional basic functions.
@@ -30,30 +29,8 @@ module Basics.Extra exposing
3029
3130@docs flip, curry, uncurry
3231
33-
34- # Deprecated functions
35-
36- These functions are deprecated and **will be removed** in the next major version of this library.
37-
38- @docs swap, atMost, atLeast, fractionalModBy, orderBy, toOrder, toOrderDesc
39-
4032-}
4133
42- import Float.Extra
43- import Order.Extra
44-
45-
46- {- | Swaps the elements in a pair.
47-
48- swap ( 1, 2 ) --> ( 2, 1 )
49-
50- @deprecated in favour of `Tuple.Extra.flip`.
51-
52- -}
53- swap : ( a , b ) -> ( b , a )
54- swap ( a, b ) =
55- ( b, a )
56-
5734
5835{- | The maximum _safe_ value for an integer, defined as `2^53 - 1`. Anything
5936larger than that and behaviour becomes mathematically unsound.
@@ -92,34 +69,6 @@ isSafeInteger number =
9269 minSafeInteger <= number && maxSafeInteger >= number
9370
9471
95- {- | Defines an upper bound for a variable.
96-
97- 42 |> atMost 0 --> 0
98-
99- -42 |> atMost 0 --> -42
100-
101- @deprecated in favour of `min`
102-
103- -}
104- atMost : comparable -> comparable -> comparable
105- atMost =
106- min
107-
108-
109- {- | Defines a lower bound for a variable.
110-
111- -42 |> atLeast 0 --> 0
112-
113- 42 |> atLeast 0 --> 42
114-
115- @deprecated in favour of `max`
116-
117- -}
118- atLeast : comparable -> comparable -> comparable
119- atLeast =
120- max
121-
122-
12372{- | Perform floating-point division (like Elm's `/` operator) that will never
12473crash the app. If the `y` argument in `safeDivide x y` is zero, we return `Nothing`.
12574
@@ -209,28 +158,6 @@ safeRemainderBy divisor x =
209158 Just ( remainderBy divisor x)
210159
211160
212- {- | Perform [modular arithmetic](https://en.wikipedia.org/wiki/Modular_arithmetic)
213- involving floating point numbers.
214-
215- The sign of the result is the same as the sign of the `modulus`
216- in `fractionalModBy modulus x`.
217-
218- fractionalModBy 2.5 5 --> 0
219-
220- fractionalModBy 2 4.5 == 0.5
221-
222- fractionalModBy 2 -4.5 == 1.5
223-
224- fractionalModBy -2 4.5 == -1.5
225-
226- @deprecated in favour of `Float.Extra.modBy`
227-
228- -}
229- fractionalModBy : Float -> Float -> Float
230- fractionalModBy =
231- Float . Extra . modBy
232-
233-
234161{- | Convert standard Elm angles (radians) to degrees.
235162
236163 inDegrees (turns 2) --> 720
@@ -288,148 +215,3 @@ This combines two arguments into a single pair.
288215uncurry : (a -> b -> c ) -> ( a , b ) -> c
289216uncurry f ( a, b ) =
290217 f a b
291-
292-
293- {- | Create an ordering function that can be used to sort
294- lists by multiple dimensions, by flattening multiple ordering functions into one.
295-
296- This is equivalent to `ORDER BY` in SQL. The ordering function will order
297- its inputs based on the order that they appear in the `List (a -> a -> Order)` argument.
298-
299- type alias Pen =
300- { model : String
301- , tipWidthInMillimeters : Float
302- }
303-
304- pens : List Pen
305- pens =
306- [ Pen "Pilot Hi-Tec-C Gel" 0.4
307- , Pen "Morning Glory Pro Mach" 0.38
308- , Pen "Pilot Hi-Tec-C Coleto" 0.5
309- ]
310-
311- order : Pen -> Pen -> Order
312- order =
313- orderBy [ toOrder .tipWidthInMillimeters, toOrder .model ]
314-
315- List.sortWith order pens
316- --> [ Pen "Morning Glory Pro Mach" 0.38
317- --> , Pen "Pilot Hi-Tec-C Gel" 0.4
318- --> , Pen "Pilot Hi-Tec-C Coleto" 0.5
319- --> ]
320-
321- If our `Pen` type alias above was represented a row in a database table, our `order` function as defined above would be equivalent
322- to this SQL clause:
323-
324- ORDER BY tipWidthInMillimeters, model
325-
326- @deprected in favor of Order.Extra.breakTies
327-
328- -}
329- orderBy : List (a -> a -> Order ) -> (a -> a -> Order )
330- orderBy =
331- Order . Extra . breakTies
332-
333-
334- {- | Helper for multi-dimensional sort.
335-
336- Takes a function that extracts a comparable value from a type `a` as a key,
337- and returns a function `a -> a -> Order`.
338-
339- This is primarily a helper function for the `orderBy` function above.
340-
341- {- Simple example: wrapping a function that turns
342- a custom type into an instance of `comparable`
343- -}
344-
345- type Color
346- = Red
347- | Yellow
348- | Green
349-
350- colorToComparable : Color -> Int
351- colorToComparable light =
352- case light of
353- Red -> 0
354- Yellow -> 1
355- Green -> 2
356-
357- colorToOrder : Color -> Color -> Order
358- colorToOrder =
359- toOrder colorToComparable
360-
361- List.sortWith
362- colorToOrder
363- [ Yellow, Yellow, Red, Green, Red ]
364- --> [ Red, Red, Yellow, Yellow, Green ]
365-
366-
367- {- More interesting example: using the property accessor
368- methods on a custom type with `toOrder`; we only need
369- this function when we want to combine multiple ordering functions into one.
370- -}
371-
372- type alias Light =
373- { color : Color
374- , action : String
375- , timeActivatedSeconds : Float
376- }
377-
378- lights : List Light
379- lights =
380- [ Light Green "Go" 60
381- , Light Yellow "Slow down" 5.5
382- , Light Red "Stop" 60
383- ]
384-
385- List.sortWith
386- ( orderBy
387- [ toOrder .timeActivatedSeconds
388- , toOrder (.color >> colorToComparable)
389- ]
390- )
391- lights
392- --> [ Light Yellow "Slow down" 5.5
393- --> , Light Red "Stop" 60
394- --> , Light Green "Go" 60
395- --> ]
396-
397- (Note that `List.sortWith colorOrder` above is identical to `List.sortBy colorToComparable`.)
398-
399- @deprecated in favour of Order.Extra.byField.
400-
401- -}
402- toOrder : (a -> comparable ) -> (a -> a -> Order )
403- toOrder selector a b =
404- Basics . compare ( selector a) ( selector b)
405-
406-
407- {- | Same as `toOrder`, with flipped comparisons to enable "sort by descending".
408-
409- type Color
410- = Red
411- | Yellow
412- | Green
413-
414- colorToComparable : Color -> Int
415- colorToComparable light =
416- case light of
417- Red -> 0
418- Yellow -> 1
419- Green -> 2
420-
421- colorToOrder : Color -> Color -> Order
422- colorToOrder =
423- toOrderDesc colorToComparable
424-
425- List.sortWith
426- colorToOrder
427- [ Yellow, Yellow, Red, Green, Red ]
428- --> [ Green, Yellow, Yellow, Red, Red ]
429-
430- @deprecated in favour of `Order.Extra.byField >> Order.Extra.reverse`
431-
432- -}
433- toOrderDesc : (a -> comparable ) -> (a -> a -> Order )
434- toOrderDesc selector a b =
435- Basics . compare ( selector b) ( selector a)
0 commit comments