]>
git.kianting.info Git - clo/blob - src/index.js
00c72f49471b506f9f0f540322eb770a8a208e8d
2 Object
.defineProperty(exports
, "__esModule", { value
: true });
3 exports
.thenDo
= exports
.charToCodepoint
= exports
.match1Char
= void 0;
4 var fs
= require('fs');
7 * it returns a function which test if the first char of the `remained` part of
8 * the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped
9 * in `Some`. Otherwise, it returns `None`.
10 * * @param c : the char to be test.
11 * @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
13 function match1Char(c
) {
15 const charToBeMatched
= m
.remained
[0];
16 if (charToBeMatched
=== c
) {
17 return { _tag
: "Some", value
: {
18 matched
: m
.matched
+ charToBeMatched
,
19 remained
: m
.remained
.substring(1)
23 return { _tag
: "None" };
27 exports
.match1Char
= match1Char
;
30 * convert the one-char string to codepoint.
31 * @param s : the string to code point.
32 * @returns if `s.length > 1` return error; otherwise, return the codepoint of `s`.
34 function charToCodepoint(s
) {
36 throw new Error("Error: the length of input string for " + s
+ "is " + s
.length
+ `,
37 however, it should be 1.`);
40 return s
.charCodeAt(0);
43 exports
.charToCodepoint
= charToCodepoint
;
45 * @description thendo(input, f, ...) like
48 function thenDo(input
, f
) {
49 if (input
._tag
== "None") {
53 let inner
= input
.value
;
57 exports
.thenDo
= thenDo
;