Skip to content

Commit 3598e8f

Browse files
authored
V2 (#40)
* Prepare v2 * Bump version
1 parent 77ee5fb commit 3598e8f

File tree

16 files changed

+35
-778
lines changed

16 files changed

+35
-778
lines changed

docs.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "elmcraft/core-extra",
44
"summary": "Utility functions for an improved experience with elm/core",
55
"license": "BSD-3-Clause",
6-
"version": "1.0.0",
6+
"version": "2.0.0",
77
"exposed-modules": [
88
"Array.Extra",
99
"Basics.Extra",

src/Array/Extra.elm

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Array.Extra exposing
66
, interweave_, andMap, map2, map3, map4, map5, zip, zip3
77
, resizelRepeat, resizerRepeat, resizelIndexed, resizerIndexed
88
, mapToList, indexedMapToList
9-
, apply, interweave
109
)
1110

1211
{-| Convenience functions for working with `Array`
@@ -46,13 +45,6 @@ module Array.Extra exposing
4645
4746
@docs mapToList, indexedMapToList
4847
49-
50-
# Deprecated functions
51-
52-
These functions are deprecated and **will be removed** in the next major version of this library.
53-
54-
@docs apply, interweave
55-
5648
-}
5749

5850
import Array exposing (Array, append, empty, initialize, length, repeat, slice)
@@ -144,7 +136,7 @@ pop array =
144136
--> fromList
145137
--> [ "turtles", "on", "turtles", "on", "turtles" ]
146138
147-
To interlace an `Array`, [`interweave`](#interweave).
139+
To interlace an `Array`, [`interweave_`](#interweave_).
148140
149141
-}
150142
intersperse : a -> Array a -> Array a
@@ -183,26 +175,6 @@ consTry maybeNewHead list =
183175
list
184176

185177

186-
{-| Apply a given `Array` of changes to all elements.
187-
If one `Array` is longer, its extra elements are not used.
188-
189-
import Array exposing (fromList, repeat)
190-
191-
repeat 5 100
192-
|> apply
193-
(fromList
194-
[ \x -> -x, identity, (+) 10 ]
195-
)
196-
--> fromList [ -100, 100, 110 ]
197-
198-
@deprecated in favour of `Array.Extra.andMap` (note the reversed argument order).
199-
200-
-}
201-
apply : Array (a -> b) -> Array a -> Array b
202-
apply changes array =
203-
map2 (\map element -> map element) changes array
204-
205-
206178
{-| Map functions taking multiple arguments over multiple arrays. Each array should be of the same length; extra elements are dropped.
207179
208180
import Array exposing (Array)
@@ -781,32 +753,6 @@ member needle array =
781753
any (\element -> element == needle) array
782754

783755

784-
{-| Place all elements of a given `Array` between all current elements.
785-
Extra elements of either `Array` are glued to the end without anything in between.
786-
787-
import Array exposing (fromList, repeat)
788-
789-
fromList [ "turtles", "turtles", "turtles" ]
790-
|> interweave (repeat 2 "on")
791-
--> fromList [ "turtles", "on", "turtles", "on", "turtles" ]
792-
793-
fromList [ "turtles", "turtles", "turtles" ]
794-
|> interweave (repeat 5 "on")
795-
--> fromList [ "turtles", "on", "turtles", "on", "turtles", "on", "on", "on" ]
796-
797-
fromList [ "turtles", "turtles", "turtles" ]
798-
|> interweave (repeat 1 "on")
799-
--> fromList [ "turtles", "on", "turtles", "turtles" ]
800-
801-
@deprecated **Beware:** For historical reasons, this function takes it's arguments in the opposite order to [`List.Extra.interweave`](List-Extra#interweave).
802-
As such, this function is deprecated in v1 and will be removed in v2. You should switch to [`interweave_`](#interweave_) which has the correct argument order. We plan to re-introduce `interweave` with the new argument order in a future release, but since the chance of subtle breakage is quite high, we will only do this gradually.
803-
804-
-}
805-
interweave : Array a -> Array a -> Array a
806-
interweave toInterweave array =
807-
interweave_ array toInterweave
808-
809-
810756
{-| Return an array that contains elements from the two provided, in alternate order.
811757
If one array runs out of items, append the items from the remaining array.
812758
@@ -821,8 +767,6 @@ If one array runs out of items, append the items from the remaining array.
821767
interweave_ (fromList [ "turtles", "turtles", "turtles" ]) (repeat 1 "on")
822768
--> fromList [ "turtles", "on", "turtles", "turtles" ]
823769
824-
See documentation for [`interweave`](#interweave) to find out why the strange name.
825-
826770
-}
827771
interweave_ : Array a -> Array a -> Array a
828772
interweave_ array toInterweave =

src/Basics/Extra.elm

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5936
larger 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
12473
crash 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.
288215
uncurry : (a -> b -> c) -> ( a, b ) -> c
289216
uncurry 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

Comments
 (0)