Skip to content

Commit

Permalink
add strip-prefix, select-keys... bump 0.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed May 7, 2021
1 parent 0a7c10e commit 15b1b58
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.3.10"
version = "0.3.11"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
19 changes: 19 additions & 0 deletions calcit/snapshots/test-map.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@
let[] (k v) pair
&+ acc v

|test-select $ quote
fn ()
log-title "|Testing select"
assert=
select-keys ({} (:a 1) (:b 2) (:c 3)) ([] :a :b)
{} (:a 1) (:b 2)
assert=
select-keys ({} (:a 1) (:b 2) (:c 3)) ([] :d)
{} (:d nil)

assert=
unselect-keys ({} (:a 1) (:b 2) (:c 3)) ([] :a :b)
{} (:c 3)
assert=
unselect-keys ({} (:a 1) (:b 2) (:c 3)) ([] :c :d)
{} (:a 1) (:b 2)

|main! $ quote
defn main! ()

Expand All @@ -174,6 +191,8 @@

test-get

test-select

do true

:proc $ quote ()
Expand Down
6 changes: 6 additions & 0 deletions calcit/snapshots/test-string.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
assert= true $ ends-with? |01234 |4
assert= false $ ends-with? |01234 |23

assert= |abc $ strip-prefix |ababc |ab
assert= |0abc $ strip-prefix |0abc |ab

assert= |aba $ strip-suffix |ababc |bc
assert= |abc0 $ strip-suffix |abc0 |bc

|test-parse $ quote
fn ()
assert= 0 $ parse-float |0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.3.10",
"version": "0.3.11",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^15.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn rest(xs: &CalcitItems) -> Result<Calcit, String> {
}
buffer.push(c)
}
Ok(Calcit::Str(s.to_owned()))
Ok(Calcit::Str(buffer.to_owned()))
}
Some(a) => Err(format!("rest expected a list, got: {}", a)),
None => Err(String::from("rest expected 1 argument")),
Expand Down
24 changes: 24 additions & 0 deletions src/cirru/calcit-core.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,30 @@
|;nil $ quote
defmacro ;nil (& _body) nil

|strip-prefix $ quote
defn strip-prefix (s piece)
if (starts-with? s piece)
substr s (count piece)
, s

|strip-suffix $ quote
defn strip-suffix (s piece)
if (ends-with? s piece)
substr s 0 (&- (count s) (count piece))
, s

|select-keys $ quote
defn select-keys (m keys)
assert "|expectd map for selecting" $ map? m
foldl keys (&{}) $ fn (acc k)
assoc acc k (&get m k)

|unselect-keys $ quote
defn unselect-keys (m keys)
assert "|expectd map for unselecting" $ map? m
foldl keys m $ fn (acc k)
dissoc acc k

|conj $ quote
defn conj (xs a)
append xs a
Expand Down

0 comments on commit 15b1b58

Please sign in to comment.