mirror of
https://github.com/srid/nixos-config.git
synced 2026-05-05 13:30:11 +08:00
- Move AI config from nix-agent-wire/srid to ./AI - Update flake input: srid/AI -> srid/nix-agent-wire - Update home modules to use local AI folder via flake.self.outPath
2.7 KiB
2.7 KiB
Relude Best Practices
When using relude prelude, follow these HLint recommendations (from https://github.com/kowainik/relude/blob/main/.hlint.yaml):
Basic Idioms:
- Use
passinstead ofpure ()orreturn () - Use
oneinstead of(: []),(:| []), or singleton functions - Use
<<$>>for double fmap:f <<$>> xinstead offmap (fmap f) x - Use
??(flap) operator:ff ?? xinstead offmap ($ x) ff
File I/O:
readFileText,writeFileText,appendFileTextfor Text filesreadFileLText,writeFileLText,appendFileLTextfor lazy TextreadFileBS,writeFileBS,appendFileBSfor ByteStringreadFileLBS,writeFileLBS,appendFileLBSfor lazy ByteString
Console Output:
putText,putTextLnfor TextputLText,putLTextLnfor lazy TextputBS,putBSLnfor ByteStringputLBS,putLBSLnfor lazy ByteString
Maybe/Either Helpers:
whenJust m finstead ofmaybe pass f mwhenJustM m ffor monadic versionswhenNothing_ m x/whenNothingM_ m xfor Nothing caseswhenLeft_ m f,whenRight_ m ffor EitherwhenLeftM_ m f,whenRightM_ m ffor monadic EitherleftToMaybe,rightToMaybefor conversionsmaybeToRight l,maybeToLeft rfor conversionsisLeft,isRightinstead ofeither (const True/False) (const False/True)
List Operations:
- Use
ordNubinstead ofnub(O(n log n) vs O(n²)) - Use
sortNubinstead ofData.Set.toList . Data.Set.fromList - Use
sortWith finstead ofsortBy (comparing f)for simple cases - Use
viaNonEmpty f xinstead offmap f (nonEmpty x) - Use
asumMap f xsinstead ofasum (map f xs) - Use
toListinstead offoldr (:) []
Monadic Operations:
andM sinstead ofand <$> sequence sorM sinstead ofor <$> sequence sallM f sinstead ofand <$> mapM f sanyM f sinstead ofor <$> mapM f sguardM finstead off >>= guardinfinitelyinstead offorever(better typed)unlessM (not <$> x)→ usewhenM xinsteadwhenM (not <$> x)→ useunlessM xinstead
State/Reader Operations:
usingReaderTinstead offlip runReaderTusingStateTinstead offlip runStateTevaluatingStateT s stinstead offst <$> usingStateT s stexecutingStateT s stinstead ofsnd <$> usingStateT s st
Transformer Lifting:
hoistMaybe minstead ofMaybeT (pure m)hoistEither minstead ofExceptT (pure m)
List Pattern Matching:
whenNotNull m fforcase m of [] -> pass; (x:xs) -> f (x :| xs)whenNotNullM m ffor monadic version
Text/ByteString Conversions:
- Use relude's
toText,toString,toLTextinstead of pack/unpack - Use relude's
encodeUtf8,decodeUtf8for UTF-8 encoding fromStrict,toStrictfor lazy/strict conversions