diff options
author | Eduardo Julian | 2022-06-16 00:48:19 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-06-16 00:48:19 -0400 |
commit | 9e2f1e76f2c8df01ed7687d934c3210fcf676bd6 (patch) | |
tree | 115fab5bd8a5f53dc0d13ce5453095324a83496f /stdlib/source/library/lux/data/text.lux | |
parent | f92c806ee8da63f04bbefbf558f6249bacdb47ea (diff) |
De-sigil-ification: suffix : [Part 13]
Diffstat (limited to 'stdlib/source/library/lux/data/text.lux')
-rw-r--r-- | stdlib/source/library/lux/data/text.lux | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 918fde82a..9c2649f55 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -26,13 +26,13 @@ ... TODO: Instead of ints, chars should be produced fron nats. ... (The JVM specifies chars as 16-bit unsigned integers) -(def: .public of_char +(def .public of_char (-> Char Text) (|>> .int "lux i64 char")) (with_template [<code> <short> <long>] - [(def: .public <long> (..of_char <code>)) - (def: .public <short> <long>)] + [(def .public <long> (..of_char <code>)) + (def .public <short> <long>)] [00 \0 null] [07 \a alarm] @@ -45,28 +45,28 @@ [34 \'' double_quote] ) -(def: .public line_feed +(def .public line_feed ..new_line) -(def: .public size +(def .public size (-> Text Nat) (|>> "lux text size")) -(def: .public (char index input) +(def .public (char index input) (-> Nat Text (Maybe Char)) (if (n.< ("lux text size" input) index) {.#Some ("lux text char" index input)} {.#None})) -(def: .public (index_since offset pattern input) +(def .public (index_since offset pattern input) (-> Nat Text Text (Maybe Nat)) ("lux text index" offset pattern input)) -(def: .public (index pattern input) +(def .public (index pattern input) (-> Text Text (Maybe Nat)) (index_since 0 pattern input)) -(def: .public (last_index part text) +(def .public (last_index part text) (-> Text Text (Maybe Nat)) (loop (again [offset 0 output (is (Maybe Nat) @@ -79,7 +79,7 @@ {.#Some offset'} (again (++ offset') output'))))) -(def: .public (starts_with? prefix x) +(def .public (starts_with? prefix x) (-> Text Text Bit) (case (index prefix x) {.#Some 0} @@ -88,7 +88,7 @@ _ false)) -(def: .public (ends_with? postfix x) +(def .public (ends_with? postfix x) (-> Text Text Bit) (case (last_index postfix x) {.#Some n} @@ -98,12 +98,12 @@ _ false)) -(def: .public (enclosed_by? boundary value) +(def .public (enclosed_by? boundary value) (-> Text Text Bit) (and (starts_with? boundary value) (ends_with? boundary value))) -(def: .public (contains? sub text) +(def .public (contains? sub text) (-> Text Text Bit) (case ("lux text index" 0 sub text) {.#Some _} @@ -112,40 +112,40 @@ _ false)) -(def: .public (prefix param subject) +(def .public (prefix param subject) (-> Text Text Text) ("lux text concat" param subject)) -(def: .public (suffix param subject) +(def .public (suffix param subject) (-> Text Text Text) ("lux text concat" subject param)) -(def: .public (enclosed [left right] content) +(def .public (enclosed [left right] content) (-> [Text Text] Text Text) (all "lux text concat" left content right)) -(def: .public (enclosed' boundary content) +(def .public (enclosed' boundary content) (-> Text Text Text) (enclosed [boundary boundary] content)) -(def: .public format +(def .public format (-> Text Text) (..enclosed' ..double_quote)) -(def: .public (clip offset size input) +(def .public (clip offset size input) (-> Nat Nat Text (Maybe Text)) (if (|> size (n.+ offset) (n.> ("lux text size" input))) {.#None} {.#Some ("lux text clip" offset size input)})) -(def: .public (clip_since offset input) +(def .public (clip_since offset input) (-> Nat Text (Maybe Text)) (let [size ("lux text size" input)] (if (n.> size offset) {.#None} {.#Some ("lux text clip" offset (n.- offset size) input)}))) -(def: .public (split_at at x) +(def .public (split_at at x) (-> Nat Text (Maybe [Text Text])) (case [(..clip 0 at x) (..clip_since at x)] [{.#Some pre} {.#Some post}] @@ -154,7 +154,7 @@ _ {.#None})) -(def: .public (split_by token sample) +(def .public (split_by token sample) (-> Text Text (Maybe [Text Text])) (do maybe.monad [index (index token sample) @@ -162,7 +162,7 @@ [_ post] (split_at (size token) post')] (in [pre post]))) -(def: .public (all_split_by token sample) +(def .public (all_split_by token sample) (-> Text Text (List Text)) (loop (again [input sample output (is (List Text) (list))]) @@ -177,14 +177,14 @@ {.#Item input} list.reversed)))) -(def: .public (replaced_once pattern replacement template) +(def .public (replaced_once pattern replacement template) (-> Text Text Text Text) (<| (maybe.else template) (do maybe.monad [[pre post] (..split_by pattern template)] (in (all "lux text concat" pre replacement post))))) -(for @.js (these (def: defined? +(for @.js (these (def defined? (macro (_ tokens lux) (case tokens (pattern (list it)) @@ -197,7 +197,7 @@ _ {.#Left ""}))) - (def: if_nashorn + (def if_nashorn (macro (_ tokens lux) (case tokens (pattern (list then else)) @@ -211,7 +211,7 @@ {.#Left ""})))) (these)) -(def: .public (replaced pattern replacement template) +(def .public (replaced pattern replacement template) (-> Text Text Text Text) (with_expansions [... Inefficient default <default> (loop (again [left "" @@ -258,34 +258,34 @@ ... Inefficient default <default>))) -(def: .public equivalence +(def .public equivalence (Equivalence Text) (implementation - (def: (= reference sample) + (def (= reference sample) ("lux text =" reference sample)))) -(def: .public order +(def .public order (Order Text) (implementation - (def: equivalence ..equivalence) + (def equivalence ..equivalence) - (def: (< reference sample) + (def (< reference sample) ("lux text <" reference sample)))) -(def: .public monoid +(def .public monoid (Monoid Text) (implementation - (def: identity "") + (def identity "") - (def: (composite left right) + (def (composite left right) ("lux text concat" left right)))) -(def: .public hash +(def .public hash (Hash Text) (implementation - (def: equivalence ..equivalence) + (def equivalence ..equivalence) - (def: (hash input) + (def (hash input) (for @.old (|> input (is (Primitive "java.lang.Object")) @@ -313,29 +313,29 @@ (n.+ ("lux text char" index input)))) hash))))))) -(def: .public together +(def .public together (-> (List Text) Text) (let [(^.open "[0]") ..monoid] (|>> list.reversed (list#mix composite identity)))) -(def: .public (interposed separator texts) +(def .public (interposed separator texts) (-> Text (List Text) Text) (case separator "" (..together texts) _ (|> texts (list.interposed separator) ..together))) -(def: .public (empty? text) +(def .public (empty? text) (-> Text Bit) (case text "" true _ false)) -(def: .public space +(def .public space Text " ") -(def: .public (space? char) +(def .public (space? char) (-> Char Bit) (with_expansions [<options> (with_template [<char>] [(pattern (.char (~~ (static <char>))))] @@ -354,7 +354,7 @@ _ false)))) -(def: .public (lower_cased value) +(def .public (lower_cased value) (-> Text Text) (for @.old (as Text @@ -377,7 +377,7 @@ (as Text ("ruby object do" "downcase" value [])))) -(def: .public (upper_cased value) +(def .public (upper_cased value) (-> Text Text) (for @.old (as Text |