Skip to content

Commit ea4420a

Browse files
committed
Fix by HLint
1 parent 31da00b commit ea4420a

File tree

3 files changed

+72
-113
lines changed
  • ron/lib/RON/Text/Serialize
  • ron-rdt/lib/RON/Data
  • ron-storage/lib/RON/Storage

3 files changed

+72
-113
lines changed

ron-rdt/lib/RON/Data/RGA.hs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,35 @@ module RON.Data.RGA
3535
)
3636
where
3737

38-
import Data.Algorithm.Diff (Diff (Both, First, Second), getGroupedDiffBy)
38+
import Data.Algorithm.Diff (Diff (Both, First, Second),
39+
getGroupedDiffBy)
40+
import Data.Bifunctor (second)
3941
import qualified Data.HashMap.Strict as HashMap
40-
import Data.Map.Strict ((!?))
42+
import Data.Map.Strict ((!?))
4143
import qualified Data.Map.Strict as Map
4244
import qualified Data.Text as Text
43-
import RON.Data.Internal
44-
( MonadObjectState,
45-
ReducedChunk (ReducedChunk, rcBody, rcRef),
46-
Reducible,
47-
Rep,
48-
Replicated (encoding),
49-
ReplicatedAsObject,
50-
ReplicatedAsPayload,
51-
Unapplied,
52-
applyPatches,
53-
fromRon,
54-
getObjectStateChunk,
55-
modifyObjectStateChunk_,
56-
newObject,
57-
newRon,
58-
objectEncoding,
59-
readObject,
60-
reduceUnappliedPatches,
61-
reducibleOpType,
62-
stateFromChunk,
63-
stateToChunk,
64-
toPayload,
65-
)
66-
import RON.Error (MonadE, errorContext, throwErrorText)
67-
import RON.Event (ReplicaClock, getEventUuid, getEventUuids)
68-
import RON.Prelude
69-
import RON.Semilattice (Semilattice)
70-
import RON.Types
71-
( ObjectRef (ObjectRef),
72-
Op (Op, opId, payload, refId),
73-
StateChunk (StateChunk),
74-
StateFrame,
75-
UUID,
76-
WireStateChunk (WireStateChunk, stateBody, stateType),
77-
)
78-
import RON.UUID (uuidVersion, pattern Zero)
45+
46+
import RON.Data.Internal (MonadObjectState,
47+
ReducedChunk (ReducedChunk, rcBody, rcRef),
48+
Reducible, Rep, Replicated (encoding),
49+
ReplicatedAsObject, ReplicatedAsPayload,
50+
Unapplied, applyPatches, fromRon,
51+
getObjectStateChunk,
52+
modifyObjectStateChunk_, newObject, newRon,
53+
objectEncoding, readObject,
54+
reduceUnappliedPatches, reducibleOpType,
55+
stateFromChunk, stateToChunk, toPayload)
56+
import RON.Error (MonadE, errorContext, throwErrorText)
57+
import RON.Event (ReplicaClock, getEventUuid, getEventUuids)
58+
import RON.Prelude
59+
import RON.Semilattice (Semilattice)
60+
import RON.Types (ObjectRef (ObjectRef),
61+
Op (Op, opId, payload, refId),
62+
StateChunk (StateChunk), StateFrame, UUID,
63+
WireStateChunk (WireStateChunk, stateBody, stateType))
64+
import RON.Util.Word (pattern B11, ls60)
65+
import RON.UUID (pattern Zero, uuidVersion)
7966
import qualified RON.UUID as UUID
80-
import RON.Util.Word (ls60, pattern B11)
8167

8268
{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}
8369

@@ -201,7 +187,7 @@ instance Reducible RgaRep where
201187
stateToChunk (RgaRep rga) = maybe [] vertexListToOps rga
202188

203189
applyPatches rga (patches, ops) =
204-
bimap id patchSetToChunks . reapplyPatchSetToState rga
190+
second patchSetToChunks . reapplyPatchSetToState rga
205191
$ foldMap patchSetFromChunk patches <> foldMap patchSetFromRawOp ops
206192

207193
reduceUnappliedPatches (patches, ops) =

ron-storage/lib/RON/Storage/FS.hs

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,59 +34,37 @@ module RON.Storage.FS
3434
)
3535
where
3636

37-
import Control.Concurrent.STM
38-
( TChan,
39-
atomically,
40-
dupTChan,
41-
newBroadcastTChanIO,
42-
writeTChan,
43-
)
44-
import Data.Bits (shiftL)
37+
import RON.Prelude
38+
39+
import Control.Concurrent.STM (TChan, atomically, dupTChan,
40+
newBroadcastTChanIO, writeTChan)
41+
import Data.Bits (shiftL)
4542
import qualified Data.ByteString.Lazy as BSL
46-
import Data.Maybe (isJust)
47-
import Network.Info (MAC (MAC), getNetworkInterfaces, mac)
48-
import RON.Epoch (EpochClock, getCurrentEpochTime, runEpochClock)
49-
import RON.Error (Error, throwErrorString)
50-
import RON.Event
51-
( EpochTime,
52-
ReplicaClock,
53-
ReplicaId,
54-
advance,
55-
applicationSpecific,
56-
getEvents,
57-
getPid,
58-
)
59-
import RON.Prelude
60-
import RON.Storage as X
61-
import RON.Storage.Backend
62-
( DocId (DocId),
63-
MonadStorage,
64-
RawDocId,
65-
changeDocId,
66-
deleteVersion,
67-
getCollections,
68-
getDocumentVersions,
69-
getDocuments,
70-
loadVersionContent,
71-
saveVersionContent,
72-
)
73-
import System.Directory
74-
( canonicalizePath,
75-
createDirectoryIfMissing,
76-
doesDirectoryExist,
77-
doesPathExist,
78-
listDirectory,
79-
makeAbsolute,
80-
removeFile,
81-
renameDirectory,
82-
)
43+
import Data.Foldable (find)
44+
import Data.Maybe (isJust)
45+
import Network.Info (MAC (MAC), getNetworkInterfaces, mac)
46+
import System.Directory (canonicalizePath, createDirectoryIfMissing,
47+
doesDirectoryExist, doesPathExist,
48+
listDirectory, makeAbsolute, removeFile,
49+
renameDirectory)
50+
import System.FilePath (makeRelative, splitDirectories, (</>))
51+
import System.FSNotify (StopListening)
8352
import qualified System.FSNotify as FSNotify
84-
import System.FSNotify (StopListening)
85-
import System.FilePath ((</>), makeRelative, splitDirectories)
86-
import System.IO (hPutStrLn, stderr)
87-
import System.IO.Error (isDoesNotExistError)
88-
import System.Random.TF (newTFGen)
89-
import System.Random.TF.Instances (random)
53+
import System.IO (hPutStrLn, stderr)
54+
import System.IO.Error (isDoesNotExistError)
55+
import System.Random.TF (newTFGen)
56+
import System.Random.TF.Instances (random)
57+
58+
import RON.Epoch (EpochClock, getCurrentEpochTime, runEpochClock)
59+
import RON.Error (Error, throwErrorString)
60+
import RON.Event (EpochTime, ReplicaClock, ReplicaId, advance,
61+
applicationSpecific, getEvents, getPid)
62+
import RON.Storage as X
63+
import RON.Storage.Backend (DocId (DocId), MonadStorage, RawDocId,
64+
changeDocId, deleteVersion,
65+
getCollections, getDocumentVersions,
66+
getDocuments, loadVersionContent,
67+
saveVersionContent)
9068

9169
-- | Environment is the dataDir
9270
newtype Storage a = Storage (ExceptT Error (ReaderT Handle EpochClock) a)
@@ -229,8 +207,7 @@ getMacAddress = do
229207
macAddress <- getMac
230208
pure $ decodeMac <$> macAddress
231209
where
232-
getMac =
233-
listToMaybe . filter (/= minBound) . map mac <$> getNetworkInterfaces
210+
getMac = find (/= minBound) . map mac <$> getNetworkInterfaces
234211
decodeMac (MAC b5 b4 b3 b2 b1 b0) =
235212
(fromIntegral b5 `shiftL` 40)
236213
+ (fromIntegral b4 `shiftL` 32)

ron/lib/RON/Text/Serialize/UUID.hs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,11 @@ serializeUuidKey
4343
-> ByteStringL
4444
serializeUuidKey prevKey prev this =
4545
BSL.fromStrict $ case uuidVariant thisFields of
46-
B00 -> minimumByLength
47-
$ unzipped thisFields
48-
: [ z
49-
| uuidVariant (split prevKey) == B00
50-
, Just z <- [zipUuid (split prevKey) thisFields]
51-
]
52-
++ [ "`" <> z
53-
| prev /= zero
54-
, uuidVariant (split prev) == B00
55-
, Just z <- [zipUuid (split prev) thisFields]
56-
]
57-
_ -> serializeUuidGeneric this
46+
B00 -> minimumByLength $
47+
unzipped thisFields
48+
: zipIfDefaultVariant prevKey this
49+
++ ["`" <> z | prev /= zero, z <- zipIfDefaultVariant prev this]
50+
_ -> serializeUuidGeneric this
5851
where
5952
thisFields = split this
6053

@@ -65,17 +58,20 @@ serializeUuidAtom
6558
-> ByteStringL
6659
serializeUuidAtom prev this =
6760
BSL.fromStrict $ case uuidVariant thisFields of
68-
B00 -> minimumByLength
69-
$ unzipped thisFields
70-
: [ z
71-
| prev /= zero
72-
, uuidVariant (split prev) == B00
73-
, Just z <- [zipUuid (split prev) thisFields]
74-
]
75-
_ -> serializeUuidGeneric this
61+
B00 -> minimumByLength $
62+
unzipped thisFields
63+
: (guard (prev /= zero) *> zipIfDefaultVariant prev this)
64+
_ -> serializeUuidGeneric this
7665
where
7766
thisFields = split this
7867

68+
zipIfDefaultVariant :: UUID -> UUID -> [ByteString]
69+
zipIfDefaultVariant prev this =
70+
[ z
71+
| uuidVariant (split prev) == B00
72+
, Just z <- [zipUuid (split prev) (split this)]
73+
]
74+
7975
unzipped :: UuidFields -> ByteString
8076
unzipped UuidFields{..} = x' <> y'
8177
where

0 commit comments

Comments
 (0)