Skip to content

Commit 838c5db

Browse files
committed
Undo formatting
1 parent 1222b7c commit 838c5db

File tree

3 files changed

+117
-117
lines changed

3 files changed

+117
-117
lines changed

src/Data/Array.purs

+101-97
Original file line numberDiff line numberDiff line change
@@ -28,99 +28,106 @@
2828
-- | allowing you to STAI.iterate over an array and accumulate effects.
2929
-- |
3030
module Data.Array
31-
( (!!)
32-
, (..)
33-
, (:)
34-
, (\\)
35-
, all
36-
, alterAt
37-
, any
38-
, catMaybes
39-
, concat
40-
, concatMap
41-
, cons
42-
, delete
43-
, deleteAt
44-
, deleteBy
45-
, difference
46-
, drop
47-
, dropEnd
48-
, dropWhile
31+
( fromFoldable
32+
, toUnfoldable
33+
, singleton
34+
, (..), range
35+
, replicate
36+
, some
37+
, many
38+
39+
, null
40+
, length
41+
42+
, (:), cons
43+
, snoc
44+
, insert
45+
, insertBy
46+
47+
, head
48+
, last
49+
, tail
50+
, init
51+
, uncons
52+
, unsnoc
53+
54+
, (!!), index
4955
, elem
56+
, notElem
5057
, elemIndex
5158
, elemLastIndex
52-
, filter
53-
, filterA
5459
, find
60+
, findMap
5561
, findIndex
5662
, findLastIndex
57-
, findMap
58-
, fold
59-
, foldM
60-
, foldMap
61-
, foldRecM
62-
, foldl
63-
, foldr
64-
, fromFoldable
65-
, group
66-
, groupAll
67-
, groupAllBy
68-
, groupBy
69-
, head
70-
, index
71-
, init
72-
, insert
7363
, insertAt
74-
, insertBy
75-
, intercalate
76-
, intersect
77-
, intersectBy
78-
, intersperse
79-
, isEmpty
80-
, last
81-
, length
82-
, many
83-
, mapMaybe
84-
, mapWithIndex
64+
, deleteAt
65+
, updateAt
66+
, updateAtIndices
8567
, modifyAt
8668
, modifyAtIndices
87-
, notElem
88-
, nub
89-
, nubBy
90-
, nubByEq
91-
, nubEq
92-
, null
93-
, partition
94-
, range
95-
, replicate
69+
, alterAt
70+
71+
, intersperse
9672
, reverse
73+
, concat
74+
, concatMap
75+
, filter
76+
, partition
77+
, splitAt
78+
, filterA
79+
, mapMaybe
80+
, catMaybes
81+
, mapWithIndex
82+
, foldl
83+
, foldr
84+
, foldMap
85+
, fold
86+
, intercalate
9787
, scanl
9888
, scanr
99-
, singleton
100-
, slice
101-
, snoc
102-
, some
89+
10390
, sort
10491
, sortBy
10592
, sortWith
106-
, span
107-
, splitAt
108-
, tail
93+
, slice
10994
, take
11095
, takeEnd
11196
, takeWhile
112-
, toUnfoldable
113-
, uncons
97+
, drop
98+
, dropEnd
99+
, dropWhile
100+
, span
101+
, group
102+
, groupAll
103+
, groupBy
104+
, groupAllBy
105+
106+
, nub
107+
, nubEq
108+
, nubBy
109+
, nubByEq
114110
, union
115111
, unionBy
116-
, unsafeIndex
117-
, unsnoc
118-
, unzip
119-
, updateAt
120-
, updateAtIndices
121-
, zip
112+
, delete
113+
, deleteBy
114+
115+
, (\\), difference
116+
, intersect
117+
, intersectBy
118+
122119
, zipWith
123120
, zipWithA
121+
, zip
122+
, unzip
123+
124+
, any
125+
, all
126+
127+
, foldM
128+
, foldRecM
129+
130+
, unsafeIndex
124131
) where
125132

126133
import Prelude
@@ -147,7 +154,7 @@ toUnfoldable xs = unfoldr f 0
147154
where
148155
len = length xs
149156
f i
150-
| i < len = Just (Tuple (unsafePartial (unsafeIndex xs i)) (i + 1))
157+
| i < len = Just (Tuple (unsafePartial (unsafeIndex xs i)) (i+1))
151158
| otherwise = Nothing
152159

153160
-- | Convert a `Foldable` structure into an `Array`.
@@ -171,7 +178,7 @@ foreign import fromFoldableImpl
171178
-- | singleton 2 = [2]
172179
-- | ```
173180
singleton :: forall a. a -> Array a
174-
singleton a = [ a ]
181+
singleton a = [a]
175182

176183
-- | Create an array containing a range of integers, including both endpoints.
177184
-- | ```purescript
@@ -244,7 +251,7 @@ foreign import length :: forall a. Array a -> Int
244251
-- |
245252
-- | Note, the running time of this function is `O(n)`.
246253
cons :: forall a. a -> Array a -> Array a
247-
cons x xs = [ x ] <> xs
254+
cons x xs = [x] <> xs
248255

249256
-- | An infix alias for `cons`.
250257
-- |
@@ -284,10 +291,8 @@ insert = insertBy compare
284291
-- |
285292
insertBy :: forall a. (a -> a -> Ordering) -> a -> Array a -> Array a
286293
insertBy cmp x ys =
287-
let
288-
i = maybe 0 (_ + 1) (findLastIndex (\y -> cmp x y == GT) ys)
289-
in
290-
unsafePartial (fromJust (insertAt i x ys))
294+
let i = maybe 0 (_ + 1) (findLastIndex (\y -> cmp x y == GT) ys)
295+
in unsafePartial (fromJust (insertAt i x ys))
291296

292297
--------------------------------------------------------------------------------
293298
-- Non-indexed reads -----------------------------------------------------------
@@ -612,16 +617,15 @@ alterAt i f xs = maybe Nothing go (xs !! i)
612617
-- | ```
613618
intersperse :: forall a. a -> Array a -> Array a
614619
intersperse a arr = case length arr of
615-
len
616-
| len < 2 -> arr
617-
| otherwise -> STA.run do
618-
let unsafeGetElem idx = unsafePartial (unsafeIndex arr idx)
619-
out <- STA.new
620-
_ <- STA.push (unsafeGetElem 0) out
621-
ST.for 1 len \idx -> do
622-
_ <- STA.push a out
623-
void (STA.push (unsafeGetElem idx) out)
624-
pure out
620+
len | len < 2 -> arr
621+
| otherwise -> STA.run do
622+
let unsafeGetElem idx = unsafePartial (unsafeIndex arr idx)
623+
out <- STA.new
624+
_ <- STA.push (unsafeGetElem 0) out
625+
ST.for 1 len \idx -> do
626+
_ <- STA.push a out
627+
void (STA.push (unsafeGetElem idx) out)
628+
pure out
625629

626630
-- | Reverse an array, creating a new array.
627631
-- |
@@ -704,7 +708,7 @@ splitAt i xs = { before: slice 0 i xs, after: slice i (length xs) xs }
704708
filterA :: forall a f. Applicative f => (a -> f Boolean) -> Array a -> f (Array a)
705709
filterA p =
706710
traverse (\x -> Tuple x <$> p x)
707-
>>> map (mapMaybe (\(Tuple x b) -> if b then Just x else Nothing))
711+
>>> map (mapMaybe (\(Tuple x b) -> if b then Just x else Nothing))
708712

709713
-- | Apply a function to each element in an array, keeping only the results
710714
-- | which contain a value, creating a new array.
@@ -1048,16 +1052,16 @@ nubBy :: forall a. (a -> a -> Ordering) -> Array a -> Array a
10481052
nubBy comp xs = case head indexedAndSorted of
10491053
Nothing -> []
10501054
Just x -> map snd $ sortWith fst $ ST.run do
1051-
-- TODO: use NonEmptyArrays here to avoid partial functions
1052-
result <- STA.unsafeThaw $ singleton x
1053-
ST.foreach indexedAndSorted \pair@(Tuple _ x') -> do
1054-
lst <- snd <<< unsafePartial (fromJust <<< last) <$> STA.unsafeFreeze result
1055-
when (comp lst x' /= EQ) $ void $ STA.push pair result
1056-
STA.unsafeFreeze result
1055+
-- TODO: use NonEmptyArrays here to avoid partial functions
1056+
result <- STA.unsafeThaw $ singleton x
1057+
ST.foreach indexedAndSorted \pair@(Tuple _ x') -> do
1058+
lst <- snd <<< unsafePartial (fromJust <<< last) <$> STA.unsafeFreeze result
1059+
when (comp lst x' /= EQ) $ void $ STA.push pair result
1060+
STA.unsafeFreeze result
10571061
where
10581062
indexedAndSorted :: Array (Tuple Int a)
10591063
indexedAndSorted = sortBy (\x y -> comp (snd x) (snd y))
1060-
(mapWithIndex Tuple xs)
1064+
(mapWithIndex Tuple xs)
10611065

10621066
-- | Remove the duplicates from an array, where element equality is determined
10631067
-- | by the specified equivalence relation, creating a new array.
@@ -1124,7 +1128,7 @@ delete = deleteBy eq
11241128
-- | ```
11251129
-- |
11261130
deleteBy :: forall a. (a -> a -> Boolean) -> a -> Array a -> Array a
1127-
deleteBy _ _ [] = []
1131+
deleteBy _ _ [] = []
11281132
deleteBy eq x ys = maybe ys (\i -> unsafePartial $ fromJust (deleteAt i ys)) (findIndex (eq x) ys)
11291133

11301134
-- | Delete the first occurrence of each element in the second array from the

src/Data/Array/NonEmpty.purs

+11-15
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ module Data.Array.NonEmpty
1010
, toUnfoldable
1111
, toUnfoldable1
1212
, singleton
13-
, (..)
14-
, range
13+
, (..), range
1514
, replicate
1615
, some
1716

1817
, length
1918

20-
, (:)
21-
, cons
19+
, (:), cons
2220
, cons'
2321
, snoc
2422
, snoc'
@@ -33,8 +31,7 @@ module Data.Array.NonEmpty
3331
, uncons
3432
, unsnoc
3533

36-
, (!!)
37-
, index
34+
, (!!), index
3835
, elem
3936
, notElem
4037
, elemIndex
@@ -97,8 +94,7 @@ module Data.Array.NonEmpty
9794
, delete
9895
, deleteBy
9996

100-
, (\\)
101-
, difference
97+
, (\\), difference
10298
, difference'
10399
, intersect
104100
, intersect'
@@ -177,7 +173,7 @@ toArray :: forall a. NonEmptyArray a -> Array a
177173
toArray (NonEmptyArray xs) = xs
178174

179175
toNonEmpty :: forall a. NonEmptyArray a -> NonEmpty Array a
180-
toNonEmpty = uncons >>> \{ head: x, tail: xs } -> x :| xs
176+
toNonEmpty = uncons >>> \{head: x, tail: xs} -> x :| xs
181177

182178
fromFoldable :: forall f a. Foldable f => f a -> Maybe (NonEmptyArray a)
183179
fromFoldable = fromArray <<< A.fromFoldable
@@ -193,7 +189,7 @@ toUnfoldable1 xs = unfoldr1 f 0
193189
where
194190
len = length xs
195191
f i = Tuple (unsafePartial unsafeIndex xs i) $
196-
if i < (len - 1) then Just (i + 1) else Nothing
192+
if i < (len - 1) then Just (i + 1) else Nothing
197193

198194
singleton :: forall a. a -> NonEmptyArray a
199195
singleton = unsafeFromArray <<< A.singleton
@@ -211,8 +207,7 @@ some
211207
:: forall f a
212208
. Alternative f
213209
=> Lazy (f (Array a))
214-
=> f a
215-
-> f (NonEmptyArray a)
210+
=> f a -> f (NonEmptyArray a)
216211
some = unsafeFromArrayF <<< A.some
217212

218213
length :: forall a. NonEmptyArray a -> Int
@@ -328,7 +323,7 @@ partition
328323
:: forall a
329324
. (a -> Boolean)
330325
-> NonEmptyArray a
331-
-> { yes :: Array a, no :: Array a }
326+
-> { yes :: Array a, no :: Array a}
332327
partition f = adaptAny $ A.partition f
333328

334329
filterA
@@ -494,10 +489,10 @@ difference xs = adaptAny $ difference' xs
494489
difference' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a
495490
difference' xs = A.difference $ toArray xs
496491

497-
intersect :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a
492+
intersect :: forall a . Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a
498493
intersect = intersectBy eq
499494

500-
intersect' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a
495+
intersect' :: forall a . Eq a => NonEmptyArray a -> Array a -> Array a
501496
intersect' = intersectBy' eq
502497

503498
intersectBy
@@ -526,6 +521,7 @@ zipWith
526521
-> NonEmptyArray c
527522
zipWith f xs ys = unsafeFromArray $ A.zipWith f (toArray xs) (toArray ys)
528523

524+
529525
zipWithA
530526
:: forall m a b c
531527
. Applicative m

0 commit comments

Comments
 (0)