Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Fluture #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

use Fluture #36

wants to merge 1 commit into from

Conversation

davidchambers
Copy link
Owner

I wrote and ran a script to verify that these changes do not change the output for a handful of projects.

Copy link
Collaborator

@Avaq Avaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, with some optional code style suggestions.

Comment on lines +55 to +58
// writeStdOut :: String -> Future Error Undefined
const writeStdOut = data => (
Future.node (callback => process.stdout.write (data, 'utf8', callback))
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I've known for a while that process.stdout.write is non-blocking, but I never knew it takes a callback. :)

Comment on lines +111 to +124
// parseFile :: Options -> String -> Future Error String
const parseFile = options => filename => (
map (promap (lines)
(unlines)
(B (snd)
(reduce (flip (line =>
pair (num => B (Pair (num + 1))
(append (parseLine (options)
(filename)
(num)
(line))))))
(Pair (1) ([])))))
(readFile (filename))
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably unnest some of this by extracting pieces:

Suggested change
// parseFile :: Options -> String -> Future Error String
const parseFile = options => filename => (
map (promap (lines)
(unlines)
(B (snd)
(reduce (flip (line =>
pair (num => B (Pair (num + 1))
(append (parseLine (options)
(filename)
(num)
(line))))))
(Pair (1) ([])))))
(readFile (filename))
);
// overLines :: (Array String -> Array String) -> String -> String
const overLines = promap (lines) (unlines);
// parseFile :: Options -> String -> Future Error String
const parseFile = options => filename => {
const parse = parseLine = (options) (filename);
const reducer = line => pair (num => B (Pair (num + 1))
(append (parse (num) (line))));
const parseLines = B (snd) (reduce (flip (reducer)) (Pair (1) ([])));
return T (readFile (filename)) (map (overLines (parseLines)));
};

Comment on lines +180 to +186
(chain (output =>
program.insertInto == null ?
writeStdOut (output) :
chain (writeFile (program.insertInto))
(map (replace (delimiters) ('$1\n\n' + output + '\n$2'))
(readFile (program.insertInto))))
(transcribe (options) (program.args)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use thrush as a poor-man's pipe operator to make the data flow and indentation a bit more natural.

Suggested change
(chain (output =>
program.insertInto == null ?
writeStdOut (output) :
chain (writeFile (program.insertInto))
(map (replace (delimiters) ('$1\n\n' + output + '\n$2'))
(readFile (program.insertInto))))
(transcribe (options) (program.args)));
(T (transcribe (options) (program.args))
(chain (output =>
program.insertInto == null ?
writeStdOut (output) :
chain (writeFile (program.insertInto))
(map (replace (delimiters) ('$1\n\n' + output + '\n$2'))
(readFile (program.insertInto))))));

Comment on lines +178 to +179
(e => { console.error (String (e)); process.exit (1); })
(_ => { process.exit (0); })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what the type of the thing your Future will reject with is, so you may not need the string cast.

Suggested change
(e => { console.error (String (e)); process.exit (1); })
(_ => { process.exit (0); })
(e => { console.error (e.stack); process.exit (1); })
(_ => { process.exit (0); })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants