Skip to content

Commit d66a384

Browse files
committed
Gets tests into compiling
1 parent d1ff0ed commit d66a384

File tree

12 files changed

+128
-143
lines changed

12 files changed

+128
-143
lines changed

docs.json

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

src/Array/Extra.elm

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ If the index is out of bounds, nothing is changed.
6767
--> fromList [ 1, 2, 3 ]
6868
6969
-}
70-
update :
71-
Int
72-
-> (element -> element)
73-
-> (Array element -> Array element)
74-
update index alter =
75-
\array ->
76-
case array |> Array.get index of
77-
Nothing ->
78-
array
70+
update : Int -> (a -> a) -> Array a -> Array a
71+
update index alter array =
72+
case array |> Array.get index of
73+
Nothing ->
74+
array
7975

80-
Just element ->
81-
array |> Array.set index (alter element)
76+
Just element ->
77+
array |> Array.set index (alter element)
8278

8379

8480
{-| Drop a given number of elements from the start.
@@ -94,10 +90,9 @@ Given a negative argument, count the end of the slice from the end.
9490
--> fromList [ 4, 5, 6 ]
9591
9692
-}
97-
sliceFrom : Int -> (Array element -> Array element)
98-
sliceFrom lengthDropped =
99-
\array ->
100-
array |> slice lengthDropped (array |> length)
93+
sliceFrom : Int -> Array a -> Array a
94+
sliceFrom lengthDropped array =
95+
array |> slice lengthDropped (array |> length)
10196

10297

10398
{-| Take a number of elements from the start.
@@ -113,7 +108,7 @@ Given a negative argument, count the beginning of the slice from the end.
113108
--> fromList [ 0, 1, 2, 3 ]
114109
115110
-}
116-
sliceUntil : Int -> (Array element -> Array element)
111+
sliceUntil : Int -> Array a -> Array a
117112
sliceUntil =
118113
slice 0
119114

@@ -129,9 +124,9 @@ sliceUntil =
129124
--> empty
130125
131126
-}
132-
pop : Array element -> Array element
127+
pop : Array a -> Array a
133128
pop =
134-
\array -> array |> slice 0 -1
129+
slice 0 -1
135130

136131

137132
{-| Place a value between all elements.
@@ -146,13 +141,12 @@ pop =
146141
To interlace an `Array`, [`interweave`](#interweave).
147142
148143
-}
149-
intersperse : element -> (Array element -> Array element)
150-
intersperse separator =
151-
\array ->
152-
array
153-
|> Array.toList
154-
|> List.intersperse separator
155-
|> Array.fromList
144+
intersperse : a -> Array a -> Array a
145+
intersperse separator array =
146+
array
147+
|> Array.toList
148+
|> List.intersperse separator
149+
|> Array.fromList
156150

157151

158152
{-| Try transforming all elements but only keep the successes.
@@ -164,27 +158,23 @@ intersperse separator =
164158
--> fromList [ 3, 5 ]
165159
166160
-}
167-
filterMap :
168-
(element -> Maybe narrowElement)
169-
-> (Array element -> Array narrowElement)
170-
filterMap tryMap =
171-
\array ->
172-
array
173-
|> Array.foldr
174-
(\el soFar -> soFar |> consTry (el |> tryMap))
175-
[]
176-
|> Array.fromList
161+
filterMap : (a -> Maybe b) -> Array a -> Array b
162+
filterMap tryMap array =
163+
array
164+
|> Array.foldr
165+
(\el soFar -> consTry (tryMap el) soFar)
166+
[]
167+
|> Array.fromList
177168

178169

179170
consTry : Maybe a -> List a -> List a
180-
consTry maybeNewHead =
181-
\list ->
182-
case maybeNewHead of
183-
Just newHead ->
184-
newHead :: list
171+
consTry maybeNewHead list =
172+
case maybeNewHead of
173+
Just newHead ->
174+
newHead :: list
185175

186-
Nothing ->
187-
list
176+
Nothing ->
177+
list
188178

189179

190180
{-| Apply a given `Array` of changes to all elements.
@@ -200,12 +190,9 @@ If one `Array` is longer, its extra elements are not used.
200190
--> fromList [ -100, 100, 110 ]
201191
202192
-}
203-
apply :
204-
Array (element -> mappedElement)
205-
-> (Array element -> Array mappedElement)
206-
apply changes =
207-
\array ->
208-
array |> map2 (\map element -> map element) changes
193+
apply : Array (a -> b) -> Array a -> Array b
194+
apply changes array =
195+
array |> map2 (\map element -> map element) changes
209196

210197

211198
{-| Apply a function to the elements in the array and collect the result in a List.
@@ -218,17 +205,9 @@ apply changes =
218205
--> [ Html.text "a", Html.text "b", Html.text "c" ]
219206
220207
-}
221-
mapToList :
222-
(element -> mappedElement)
223-
-> (Array element -> List mappedElement)
224-
mapToList elementChange =
225-
\array ->
226-
array
227-
|> Array.foldr
228-
(\element soFar ->
229-
soFar |> (::) (element |> elementChange)
230-
)
231-
[]
208+
mapToList : (a -> b) -> Array a -> List b
209+
mapToList fn array =
210+
Array.foldr (\element soFar -> fn element :: soFar) [] array
232211

233212

234213
{-| Transform all elements with their indexes as the first argument

src/Order/Extra.elm

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ a standard deck of cards. You might define it as:
3737
3838
With this representation, you could define an ordering for `Card` values compositionally:
3939
40-
import Ordering exposing (Ordering)
40+
import Order.Extra
4141
42-
cardOrdering : Ordering Card
42+
cardOrdering : Card -> Card -> Order
4343
cardOrdering =
4444
Ordering.byFieldWith suiteOrdering .suite
4545
|> Ordering.breakTiesWith
4646
(Ordering.byFieldWith valueOrdering .value)
4747
48-
suiteOrdering : Ordering Suite
48+
suiteOrdering : Suite -> Suite -> Order
4949
suiteOrdering =
5050
Ordering.explicit [ Clubs, Hearts, Diamonds, Spades ]
5151
52-
valueOrdering : Ordering Value
52+
valueOrdering : Value -> Value -> Order
5353
valueOrdering =
5454
Ordering.explicit
5555
[ Two
@@ -97,6 +97,7 @@ to sort a deck of cards you can use `cardOrdering` directly:
9797
-}
9898

9999
import Regex exposing (Regex)
100+
import String.Normalize
100101

101102

102103
fromLessThan : (a -> a -> Bool) -> a -> a -> Order
@@ -124,9 +125,9 @@ other and less than anything in the list.
124125
| Sat
125126
| Sun
126127
127-
dayOrdering : Ordering Day
128+
dayOrdering : Day -> Day -> Order
128129
dayOrdering =
129-
Ordering.explicit
130+
Order.Extra.explicit
130131
[ Mon, Tue, Wed, Thu, Fri, Sat, Sun ]
131132
132133
-}
@@ -184,10 +185,10 @@ field selected by the given function.
184185
185186
type alias Point = { x : Int, y : Int }
186187
187-
List.sort (Ordering.byField .x) [Point 3 5, Point 1 6]
188-
== [Point 1 6, Point 3 5]
189-
List.sort (Ordering.byField .y) [Point 3 5, Point 1 6]
190-
== [Point 3 5, Point 1 6]
188+
List.sortWith (Order.Extra.byField .x) [Point 3 5, Point 1 6]
189+
--> [Point 1 6, Point 3 5]
190+
List.sortWith (Order.Extra.byField .y) [Point 3 5, Point 1 6]
191+
--> [Point 3 5, Point 1 6]
191192
192193
-}
193194
byField : (a -> comparable) -> a -> a -> Order
@@ -198,23 +199,19 @@ byField =
198199
{-| Produces an ordering that orders its elements using the given ordering on the
199200
field selected by the given function.
200201
202+
cards : List Card
201203
cards =
202-
[ { value = Two, suite = Spades }
203-
, { value = King, suite = Hearts }
204-
]
204+
[ Card King Hearts, Card King Hearts ]
205205
206-
List.sort
207-
(Ordering.byFieldWith valueOrdering .value)
206+
List.sortWith
207+
(Order.Extra.byFieldWith valueOrdering .value)
208208
cards
209-
== [ { value = Two, suite = Spades }
210-
, { value = King, suite = Hearts }
211-
]
212-
List.sort
213-
(Ordering.byFieldWith suiteOrdering .suite)
209+
== [ Card Two Spades, Card King Hearts]
210+
211+
List.sortWith
212+
(Order.Extra.byFieldWith suiteOrdering .suite)
214213
cards
215-
== [ { value = King, suite = Hearts }
216-
, { value = Two, suite = Spades }
217-
]
214+
== [ Card King Hearts, Card Two Spades ]
218215
219216
-}
220217
byFieldWith : (b -> b -> Order) -> (a -> b) -> a -> a -> Order
@@ -230,10 +227,10 @@ function chaining with `|>`.)
230227
type alias Point =
231228
{ x : Int, y : Int }
232229
233-
pointOrdering : Ordering Point
230+
pointOrdering : Point -> Point -> Order
234231
pointOrdering =
235-
Ordering.byField .x
236-
|> Ordering.breakTiesWith (Ordering.byField .y)
232+
Order.Extra.byField .x
233+
|> Order.Extra.breakTiesWith (Order.Extra.byField .y)
237234
238235
-}
239236
breakTiesWith : (a -> a -> Order) -> (a -> a -> Order) -> a -> a -> Order
@@ -265,9 +262,9 @@ a type such as:
265262
266263
you could use `byRank` to sort all the normal cards before the jokers like so:
267264
268-
jokerCardOrdering : Ordering JokerCard
265+
jokerCardOrdering : JokerCard -> JokerCard -> Order
269266
jokerCardOrdering =
270-
Ordering.byRank
267+
Order.Extra.byRank
271268
(\card ->
272269
case card of
273270
NormalCard _ _ ->
@@ -280,11 +277,11 @@ you could use `byRank` to sort all the normal cards before the jokers like so:
280277
case ( x, y ) of
281278
( NormalCard v1 s1, NormalCard v2 s2 ) ->
282279
suiteOrdering s1 s2
283-
|> Ordering.ifStillTiedThen
280+
|> Order.Extra.ifStillTiedThen
284281
(valueOrdering v1 v2)
285282
286283
_ ->
287-
Ordering.noConflicts
284+
EQ
288285
)
289286
290287
More generally, the expected pattern is that for each case in your type, you assign
@@ -323,9 +320,9 @@ ifStillTiedThen tiebreaker mainOrder =
323320
{-| Returns an ordering that reverses the input ordering.
324321
325322
List.sortWith
326-
(Ordering.reverse Ordering.natural)
323+
(Order.Extra.reverse compare)
327324
[ 1, 2, 3, 4, 5 ]
328-
== [ 5, 4, 3, 2, 1 ]
325+
--> [ 5, 4, 3, 2, 1 ]
329326
330327
-}
331328
reverse : (a -> a -> Order) -> a -> a -> Order
@@ -343,19 +340,19 @@ reverse ordering x y =
343340

344341
{-| Determines if the given list is ordered according to the given ordering.
345342
346-
Ordering.isOrdered Ordering.natural [ 1, 2, 3 ]
347-
== True
343+
Order.Extra.isOrdered compare [ 1, 2, 3 ]
344+
--> True
348345
349-
Ordering.isOrdered Ordering.natural [ 2, 1, 3 ]
350-
== False
346+
Order.Extra.isOrdered compare [ 2, 1, 3 ]
347+
--> False
351348
352-
Ordering.isOrdered Ordering.natural []
353-
== True
349+
Order.Extra.isOrdered compare []
350+
--> True
354351
355-
Ordering.isOrdered
356-
(Ordering.reverse Ordering.natural)
352+
Order.Extra.isOrdered
353+
(Order.Extra.reverse compare)
357354
[ 1, 2, 3 ]
358-
== False
355+
--> False
359356
360357
-}
361358
isOrdered : (a -> a -> Order) -> List a -> Bool
@@ -433,7 +430,7 @@ greaterThanBy ordering x y =
433430

434431
{-| Compare two strings naturally.
435432
436-
List.sortWith NaturalOrdering.compare ["a10", "a2"]
433+
List.sortWith Order.Extra.natural ["a10", "a2"]
437434
--> ["a2", "a10"]
438435
439436
Without full I18n support, this is probably the best way to sort
@@ -495,7 +492,7 @@ chunkRegex =
495492

496493
toComparableString : String -> String
497494
toComparableString =
498-
String.toLower << String.Extra.removeDiacritics
495+
String.toLower << String.Normalize.removeDiacritics
499496

500497

501498
toChunks : String -> List Chunk

src/String/Extra.elm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ nonBlank string =
873873
-}
874874
removeAccents : String -> String
875875
removeAccents string =
876+
-- TODO: I think the better implementation is in the String.Normalize.Diacritics module.
877+
-- TODO: We should verify this is true and merge the implementations.
876878
if String.isEmpty string then
877879
string
878880

src/String/Normalize.elm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ module String.Normalize exposing
1717
1818
-}
1919

20+
import Array
2021
import Char
2122
import Dict
2223
import Set exposing (Set)
2324
import String.Normalize.Diacritics as Diacritics
24-
import Array
2525

2626

2727
{-| `removeDiacritics` removes diactritics, it will expand
@@ -30,7 +30,6 @@ All non latin characters are untouched.
3030
3131
removeDiacritics "La liberté commence où l'ignorance finit."
3232
33-
3433
--> "La liberte commence ou l'ignorance finit."
3534
removeDiacritics "é()/& abc" --> "e()/& abc"
3635

0 commit comments

Comments
 (0)