Skip to content

Commit

Permalink
refine implementations for filter; bump 0.4.22
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Aug 27, 2021
1 parent 8a0cf6c commit 36d1549
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 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.4.21"
version = "0.4.22"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions calcit/snapshots/test-list.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
fn (x) (&> x 3)
[] 4 5 6 7 8 9

assert=
.filter (range 10)
fn (x) (&> x 3)
[] 4 5 6 7 8 9

assert=
filter-not (range 10)
fn (x) (&> x 3)
Expand Down
14 changes: 14 additions & 0 deletions calcit/snapshots/test-map.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@
&> v 2
{} (:c 3) (:d 4)

assert=
.filter
{} (:a 1) (:b 2) (:c 3) (:d 4)
fn (pair) $ let[] (k v) pair
&> v 2
{} (:c 3) (:d 4)

assert=
.filter-kv
{} (:a 1) (:b 2) (:c 3) (:d 4)
fn (k v)
&> v 2
{} (:c 3) (:d 4)

|test-native-map-syntax $ quote
defn test-native-map-syntax ()

Expand Down
6 changes: 6 additions & 0 deletions calcit/snapshots/test-nil.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@

assert= ([]) (.to-list nil)
assert= ({}) (.to-map nil)

assert= nil
.map nil inc

assert= nil
.filter nil inc
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.4.21",
"version": "0.4.22",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^16.7.2",
Expand Down
49 changes: 33 additions & 16 deletions src/cirru/calcit-core.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -461,23 +461,25 @@

|filter $ quote
defn filter (xs f)
foldl xs (empty xs)
fn (acc x)
if (f x) (&coll-append acc x) acc
.filter xs f

|filter-not $ quote
defn filter-not (xs f)
reduce xs (empty xs)
.filter xs $ fn (x) $ not $ f x

|&map:filter $ quote
defn &map:filter (xs f)
reduce xs (&{})
fn (acc x)
if-not (f x) (&coll-append acc x) acc
let[] (k v) x
if (f x) (&map:assoc acc k v) acc

|&coll-append $ quote
defn &coll-append (xs a)
if (list? xs) (append xs a)
if (set? xs) (&include xs a)
if (map? xs)
&map:add-entry xs a
raise "|&coll-append expected a collection"
|&map:filter-kv $ quote
defn &map:filter-kv (xs f)
reduce xs (&{})
fn (acc x)
let[] (k v) x
if (f k v) (&map:assoc acc k v) acc

|&map:add-entry $ quote
defn &map:add-entry (xs pair)
Expand All @@ -486,6 +488,18 @@
let[] (k v) pair
&map:assoc xs k v

|&list:filter $ quote
defn &list:filter (xs f)
reduce xs ([])
fn (acc x)
if (f x) (append acc x) acc

|&set:filter $ quote
defn &set:filter (xs f)
reduce xs (#{})
fn (acc x)
if (f x) (&include acc x) acc

|empty $ quote
defn empty (x)
if (nil? x) nil
Expand Down Expand Up @@ -852,7 +866,7 @@
|[,] $ quote
defmacro [,] (& body)
&let
xs $ filter body
xs $ &list:filter body
fn (x) (/= x ',)
quasiquote $ [] ~@xs

Expand Down Expand Up @@ -1005,7 +1019,7 @@
|{,} $ quote
defmacro {,} (& body)
&let
xs $ filter body
xs $ &list:filter body
fn (x) (not= x ',)
quasiquote
pairs-map $ section-by ([] ~@xs) 2
Expand Down Expand Up @@ -1290,6 +1304,8 @@
:dissoc &map:dissoc
:empty $ defn &map:empty (x) (&{})
:empty? &map:empty?
:filter &map:filter
:filter-kv &map:filter-kv
:get &map:get
:get-in get-in
:includes? &map:includes?
Expand Down Expand Up @@ -1343,7 +1359,7 @@
:each each
:empty $ defn &list:empty (x) ([])
:empty? &list:empty?
:filter filter
:filter &list:filter
:filter-not filter-not
:find-index find-index
:foldl $ defn foldl (xs v0 f) (foldl xs v0 f)
Expand Down Expand Up @@ -1395,6 +1411,7 @@
:to-string $ defn &nil:to-string (_) |
:to-number $ defn &nil:to-number (_) 0
:map $ defn &nil:map (_ _f) nil
:filter $ defn &nil:filter (_ _f) nil
:bind $ defn &nil:bind (_ _f) nil
:mappend $ defn &nil:mappend (_ x) x
:apply $ defn &nil:apply (_ _f) nil
Expand Down Expand Up @@ -1498,7 +1515,7 @@
|&list:filter-pair $ quote
defn &list:filter-pair (xs f)
if (list? xs)
filter xs $ defn %filter-pair (pair)
&list:filter xs $ defn %filter-pair (pair)
assert "|expected a pair" $ and (list? pair) $ = 2 $ count pair
f (nth pair 0) (nth pair 1)
raise "|expected list or map from `filter-pair`"
2 changes: 1 addition & 1 deletion ts-src/calcit.procs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CALCIT VERSION
export const calcit_version = "0.4.21";
export const calcit_version = "0.4.22";

import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
import { parse } from "@cirru/parser.ts";
Expand Down

0 comments on commit 36d1549

Please sign in to comment.