Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active January 2, 2021 22:55
Show Gist options
  • Save dewey92/43ab6916f4b22e6b7893c005c62126b7 to your computer and use it in GitHub Desktop.
Save dewey92/43ab6916f4b22e6b7893c005c62126b7 to your computer and use it in GitHub Desktop.
FsService - purs
module Main where
import Prelude
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Aff (Aff, launchAff_)
import Node.FS.Aff as FS
import Node.Buffer as Buffer
import Node.Encoding (Encoding(..))
type Path = String
class Monad m <= FsService m where -- [1]
exists :: Path -> m Boolean
create :: Path -> String -> m Unit
initProject :: ∀ m.
FsService m => -- [2]
String -> m Unit
initProject projectName = do
doesExist <- exists projectName -- [3]
if doesExist
then pure unit
else create projectName "Generated content" -- [4]
instance affFsService :: FsService Aff where -- [1]
exists path = FS.exists path
create path content = do
FS.mkdir path
buff <- liftEffect $ Buffer.fromString "Yoo" UTF8
FS.writeFile path buff
main :: Effect Unit
main = launchAff_ do
initProject "my-awesome-project"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment