lines-unlines
v1.0.0
Published
Haskell's lines and unlines in TypeScript.
Downloads
228
Maintainers
Readme
lines-unlines
Haskell's lines
and unlines
in TypeScript.
Installation
npm install --save lines-unlines
Usage
import { lines, unlines } from "lines-unlines";
lines("one\ntwo\n"); // ["one","two"]
unlines(["one", "two"]); // "one\ntwo\n"
For details, refer to the Haskell documentation.
Note in particular that lines
is not the same function as _ => _.split("\n")
, and unlines
is not the same as _ => _.join("\n")
.
Note also that, strictly speaking, neither lines
nor unlines
is the other's inverse, even though Hackage (as of 2019‑07‑26) says that "unlines
is an inverse operation to lines
".
For example, unlines (lines "a")
evaluates to "a\n"
, and lines (unlines ["\n"])
evaluates to ["", ""]
.
Contribute
npm run verify
lints, builds and tests the package.
Test cases can be generated using GHCi* (Haskell's REPL, included in the Haskell Platform):
$ ghci Spec.hs
*Main> spec lines ["", "one"]
*Main> spec unlines [[], ["one"]]
The output can then be pasted into index.test.ts
.
* If you have the Nix package manager, you can run nix-shell
to get a shell with ghci
on the path.