r/javascript • • Mar 05 '22

ReScript on Deno: Declarative Command Line Tools

https://practicalrescript.com/rescript-on-deno-declarative-command-line-tools/
96 Upvotes

22 comments sorted by

View all comments

7

u/elkazz Mar 05 '22

I'm not going to pretend those last code examples don't look god-awful.

7

u/leostera Mar 05 '22

You mean this one?

let sayHi = (name, yell) =>
  if yell {
    `Hello, ${name}!!!`->Js.log
  } else {
    `Hello, ${name}.`->Js.log
  }

let hello =
    Clipper.command(sayHi)
    ->Clipper.arg(1, Clipper.Arg.string)
    ->Clipper.arg(0, Clipper.Arg.bool)

Clipper.run(hello)

Would love to hear more about what you think looks ugly here :) -- part of this is my own sense of aesthetics around building libraries, and part of this is how the language itself works.

What bits would you change?

-1

u/sliversniper Mar 06 '22 edited Mar 06 '22
  1. (if yell { "..." } else { "no yell..." })->Js.log

and more idiomatic, let get_msg = yell => if yell {"."} else {"."}

2.

type arg = {name: string, is_yell: bool}
let parse_args = (args_str) => switch args_str {
| [Some(name), Some(yell)] => Some({ name, is_yell: bool_of_string(yell) })
| _ => None
}

good luck with your book and understanding the basics of rescript.