Skip to content

Commit

Permalink
Fix all non-exhaustive pattern matches
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Mar 16, 2024
1 parent 2e580ba commit 5d7d39c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions tasklite-core/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ library:
- protolude
- QuickCheck
- quickcheck-instances
- random
- read-editor
- simple-sql-parser
- sqlite-simple
Expand Down
36 changes: 18 additions & 18 deletions tasklite-core/source/ImportExport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Protolude (
import Protolude qualified as P

import Config (Config (dataDir, dbName))
import Control.Arrow ((>>>))
import Data.Aeson as Aeson (
FromJSON (parseJSON),
ToJSON,
Expand Down Expand Up @@ -126,6 +127,7 @@ import Text.PortableLines.ByteString.Lazy (lines8)
import Time.System (timeCurrent)
import Utils (
IdText,
emptyUlid,
parseUlidText,
parseUtc,
setDateTime,
Expand Down Expand Up @@ -156,23 +158,23 @@ instance FromJSON Annotation where


annotationToNote :: Annotation -> Note
annotationToNote annot@Annotation{entry = entry, description = description} =
annotationToNote annot@Annotation{entry, description} = do
let
utc = fromMaybe (timeFromElapsedP 0 :: DateTime) (parseUtc entry)
Right ulidGenerated = (ulidFromInteger . abs . toInteger . hash) annot
ulidCombined = setDateTime ulidGenerated utc
in
Note
{ ulid = (T.toLower . show) ulidCombined
, body = description
}
utc = entry & parseUtc & fromMaybe (timeFromElapsedP 0 :: DateTime)
ulidGeneratedRes = annot & (hash >>> toInteger >>> abs >>> ulidFromInteger)
ulidCombined = (ulidGeneratedRes & P.fromRight emptyUlid) `setDateTime` utc

Note
{ ulid = (T.toLower . show) ulidCombined
, body = description
}


textToNote :: DateTime -> Text -> Note
textToNote utc body =
let
Right ulidGenerated = (ulidFromInteger . abs . toInteger . hash) body
ulidCombined = setDateTime ulidGenerated utc
ulidGeneratedRes = body & (hash >>> toInteger >>> abs >>> ulidFromInteger)
ulidCombined = (ulidGeneratedRes & P.fromRight emptyUlid) `setDateTime` utc
in
Note
{ ulid = (T.toLower . show) ulidCombined
Expand Down Expand Up @@ -428,8 +430,8 @@ instance FromJSON ImportTask where

o_ulid <- o .:? "ulid"
let
Right ulidGenerated = (ulidFromInteger . abs . toInteger . hash) tempTask
ulidCombined = setDateTime ulidGenerated createdUtc
ulidGeneratedRes = tempTask & (hash >>> toInteger >>> abs >>> ulidFromInteger)
ulidCombined = (ulidGeneratedRes & P.fromRight emptyUlid) `setDateTime` createdUtc
ulid =
T.toLower $
fromMaybe
Expand Down Expand Up @@ -503,8 +505,7 @@ emailToImportTask email@(Message headerFields msgBody) =
Task.body task
<> ( msgBody
& lines8
<&> TL.decodeUtf8
<&> toStrict
<&> (TL.decodeUtf8 >>> toStrict)
& T.unlines
& T.dropEnd 1
)
Expand All @@ -530,9 +531,8 @@ emailToImportTask email@(Message headerFields msgBody) =
Email.Date emailDate ->
let
utc = zonedTimeToDateTime emailDate
Right ulidGenerated =
(ulidFromInteger . abs . toInteger . hash) $ (show email :: Text)
ulidCombined = setDateTime ulidGenerated utc
ulidGeneratedRes = (email & show :: Text) & (hash >>> toInteger >>> abs >>> ulidFromInteger)
ulidCombined = (ulidGeneratedRes & P.fromRight emptyUlid) `setDateTime` utc
in
ImportTask
task
Expand Down
13 changes: 11 additions & 2 deletions tasklite-core/source/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ import Data.Text as T (
)
import Data.Time (UTCTime, ZonedTime, addUTCTime, zonedTimeToUTC)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)
import Data.ULID (ULID (ULID, random))
import Data.ULID.Random (ULIDRandom)
import Data.ULID (ULID (ULID, random, timeStamp))
import Data.ULID.Random (ULIDRandom, mkULIDRandom)
import Data.ULID.TimeStamp (ULIDTimeStamp, mkULIDTimeStamp)
import Prettyprinter (Doc, Pretty (pretty), softline)
import Prettyprinter.Render.Terminal (
Expand All @@ -94,6 +94,7 @@ import Config (
Hook (body, filePath, interpreter),
)
import Control.Arrow ((>>>))
import System.Random (mkStdGen)


type IdText = Text
Expand All @@ -117,6 +118,14 @@ zeroTime :: DateTime
zeroTime = timeFromElapsedP 0


emptyUlid :: ULID
emptyUlid =
ULID
{ timeStamp = mkULIDTimeStamp 0
, random = mkULIDRandom (mkStdGen 0) & P.fst
}


utcFormatReadable :: TimeFormatString
utcFormatReadable =
toFormat ("YYYY-MM-DD H:MI:S" :: [Char])
Expand Down
1 change: 1 addition & 0 deletions tasklite-core/tasklite-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ library
, process
, protolude
, quickcheck-instances
, random
, read-editor
, simple-sql-parser
, sqlite-simple
Expand Down

0 comments on commit 5d7d39c

Please sign in to comment.