From 534cc0001c9c48ccbb80233aa83fd58656abca2b Mon Sep 17 00:00:00 2001 From: theory friction practice Date: Mon, 12 Jun 2017 20:49:04 -0400 Subject: [PATCH] length and match --- docs/accessors.html | 16 ++- docs/array.html | 119 ++++++++++++++++++++-- docs/cast.html | 12 ++- docs/compare.html | 10 ++ docs/group.html | 17 +++- docs/has.html | 10 ++ docs/index.html | 55 +++++++--- docs/iterable.html | 23 ++++- docs/length.html | 238 +++++++++++++++++++++++++++++++++++++++++++ docs/manipulate.html | 34 +++++-- docs/match.html | 156 ++++++++++++++++++++++++++++ docs/reducers.html | 10 ++ docs/spread.html | 25 ++++- src/spread.js | 10 +- 14 files changed, 682 insertions(+), 53 deletions(-) create mode 100644 docs/length.html create mode 100644 docs/match.html diff --git a/docs/accessors.html b/docs/accessors.html index a235c9a..11ca384 100644 --- a/docs/accessors.html +++ b/docs/accessors.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -100,7 +110,7 @@

accessors.js

import { asMap, } from './cast';
-import { spread, spreadK, spreadKV, spreadV, } from './spread';
+import { spread, spreadK, spreadV, } from './spread'; @@ -220,7 +230,9 @@

accessors.js

-
export const lastV = (c = []) => last(spreadV(c));
+
export const lastV = (c = []) => last(spreadV(c));
+
+export const rest = coll => spread(coll).slice(1);
diff --git a/docs/array.html b/docs/array.html index 0b0b551..25a3776 100644 --- a/docs/array.html +++ b/docs/array.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -110,8 +120,9 @@

array.js

-

map :: Iterable<a> -> (a->b) -> [b]
returns an Iterable of the return values of a -function called on each element of an iterable

+

map :: Iterable<a> -> (a->b) -> [b] +returns an Iterable of the return values of a +function called on each element of an iterable

@@ -126,12 +137,13 @@

array.js

-

reduce :: Iterable<a> -> ((a->b), b) -> b
returns the accumulated value of a function -called on each element of an iterable

+

mapTo :: (a->b) -> Iterable<a> -> [b] +returns an Iterable of the return values of a +function called on each element of an iterable

-
export const reduce = coll => (fn, init) => spread(coll).reduce(fn, init);
+
export const mapTo = fn => coll => map(coll)(fn);
@@ -142,11 +154,13 @@

array.js

-

filter :: Iterable<a> -> (a->bool) -> [a]
returns the iterable’s values which return true for a given function

+

reduce :: Iterable<a> -> ((a->b), b) -> b +returns the accumulated value of a function +called on each element of an iterable

-
export const filter = coll => fn => spread(coll).filter(fn);
+
export const reduce = coll => (fn, init) => spread(coll).reduce(fn, init);
@@ -157,11 +171,13 @@

array.js

-

every :: Iterable<a> -> (a->bool) -> bool
checks if every element of an iterable returns true for a given function

+

reduceBy :: ((a->b), b) -> Iterable<a> -> b +returns the accumulated value of a function +called on each element of an iterable

-
export const every = coll => fn => spread(coll).every(fn);
+
export const reduceBy = (fn, init) => coll => spread(coll).reduce(fn, init);
@@ -172,7 +188,72 @@

array.js

-

some :: Iterable<a> -> (a->b) -> [b]
checks if any element of an iterable returns true for a given function

+

filter :: Iterable<a> -> (a->bool) -> [a] +returns the iterable’s values which return true for a given function

+ + + +
export const filter = coll => fn => spread(coll).filter(fn);
+ + + + +
  • +
    + +
    + +
    +

    filtBy :: (a->bool) -> Iterable<a> -> [a] +returns the iterable’s values which return true for a given function

    + +
    + +
    export const filtBy = fn => coll => filter(coll)(fn);
    + +
  • + + +
  • +
    + +
    + +
    +

    every :: Iterable<a> -> (a->bool) -> bool +checks if every element of an iterable returns true for a given function

    + +
    + +
    export const every = coll => fn => spread(coll).every(fn);
    + +
  • + + +
  • +
    + +
    + +
    +

    everyPass :: (a->bool) -> Iterable<a> -> bool +checks if every element of an iterable returns true for a given function

    + +
    + +
    export const everyPass = fn => coll => every(coll)(fn);
    + +
  • + + +
  • +
    + +
    + +
    +

    some :: Iterable<a> -> (a->b) -> [b] +checks if any element of an iterable returns true for a given function

    @@ -180,6 +261,24 @@

    array.js

  • + +
  • +
    + +
    + +
    +

    somePass :: (a->b) -> Iterable<a> -> [b] +checks if any element of an iterable returns true for a given function

    + +
    + +
    export const somePass = fn => coll => some(coll)(fn);
    +
    +export const findBy = matchFunc => coll => spread(coll).find(matchFunc);
    + +
  • + diff --git a/docs/cast.html b/docs/cast.html index cc4c41f..1613fcc 100644 --- a/docs/cast.html +++ b/docs/cast.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -99,7 +109,7 @@

    cast.js

    -
    import { spread,  spreadKV, } from './spread';
    +
    import { spread, spreadKV, } from './spread';
    diff --git a/docs/compare.html b/docs/compare.html index c84a442..76f9bd7 100644 --- a/docs/compare.html +++ b/docs/compare.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js diff --git a/docs/group.html b/docs/group.html index 444a569..f8d4f07 100644 --- a/docs/group.html +++ b/docs/group.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -99,7 +109,8 @@

    group.js

    -
    import { iterify, } from './iterable';
    +
    import { iterify, } from './iterable';
    +import { first, rest, } from './accessors';
    @@ -235,7 +246,9 @@

    group.js

    -
    export const appendBin = (c, v) => append(c)(v);
    +
    export const appendBin = (c, v) => append(c)(v);
    +
    +export const turn = coll => append(rest(coll))(first(coll));
    diff --git a/docs/has.html b/docs/has.html index e8b392a..d2e650d 100644 --- a/docs/has.html +++ b/docs/has.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js diff --git a/docs/index.html b/docs/index.html index 1609a2a..6bbc9e2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -95,7 +105,7 @@

    index.js

    -

    exports iterable

    +

    exports iterable

    @@ -110,11 +120,11 @@

    index.js

    -

    exports spread

    +

    exports array

    -
    export * from './spread';
    +
    export * from './array';
    @@ -125,11 +135,11 @@

    index.js

    -

    exorts group

    +

    exports spread

    -
    export * from './group';
    +
    export * from './spread';
    @@ -140,11 +150,11 @@

    index.js

    -

    exports has

    +

    exorts group

    -
    export * from './has';
    +
    export * from './group';
    @@ -155,11 +165,11 @@

    index.js

    -

    exports reducers

    +

    exports has

    -
    export * from './reducers';
    +
    export * from './has';
    @@ -170,11 +180,11 @@

    index.js

    -

    exports compare

    +

    exports reducers

    -
    export * from './compare';
    +
    export * from './reducers';
    @@ -185,11 +195,11 @@

    index.js

    -

    exports manipulate

    +

    exports compare

    -
    export * from './manipulate';
    +
    export * from './compare';
    @@ -200,11 +210,11 @@

    index.js

    -

    exports accessors

    +

    exports manipulate

    -
    export * from './accessors';
    +
    export * from './manipulate';
    @@ -215,6 +225,21 @@

    index.js

    +

    exports accessors

    + + + +
    export * from './accessors';
    + + + + +
  • +
    + +
    + +

    exports cast

    diff --git a/docs/iterable.html b/docs/iterable.html index 58f77c9..934a7c8 100644 --- a/docs/iterable.html +++ b/docs/iterable.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -95,7 +105,8 @@

    iterable.js

    -

    isIterable :: obj -> bool
    checks if an object is iterable

    +

    isIterable :: obj -> bool +checks if an object is iterable

    @@ -110,7 +121,8 @@

    iterable.js

    -

    iterify :: obj -> iterable
    returns the object or an Iterable containging the object

    +

    iterify :: obj -> iterable +returns the object or an Iterable containging the object

    @@ -125,7 +137,8 @@

    iterable.js

    -

    isRemovable :: obj -> bool
    checks if an object has the delete method

    +

    isRemovable :: obj -> bool +checks if an object has the delete method

    @@ -156,7 +169,7 @@

    iterable.js

    -

    removify :: obj -> [map|set] +

    removify :: obj -> [map|set] returns the object or an Iterable containging the object

    @@ -172,7 +185,7 @@

    iterable.js

    -

    hasify :: obj -> [map|set] +

    hasify :: obj -> [map|set] returns the object or an Iterable containging the object

    diff --git a/docs/length.html b/docs/length.html new file mode 100644 index 0000000..0a2ea11 --- /dev/null +++ b/docs/length.html @@ -0,0 +1,238 @@ + + + + + length.js + + + + + +
    +
    + +
    + +
      + +
    • +
      +

      length.js

      +
      +
    • + + + +
    • +
      + +
      + +
      + +
      + +
      import { spread, } from './spread';
      + +
    • + + +
    • +
      + +
      + +
      +

      len :: Iterable<a> -> Int
      returns the length of an iterablerns the length of an iterable

      + +
      + +
      export const len = coll => spread(coll).length;
      + +
    • + + +
    • +
      + +
      + +
      +

      isEmpty :: Iterable<a> -> bool
      checks if the collection is empty

      + +
      + +
      export const isEmpty = coll => len(coll) === 0;
      + +
    • + + +
    • +
      + +
      + +
      +

      xEmpty :: Iterable<a> -> bool
      checks if the collection is non empty

      + +
      + +
      export const xEmpty = coll => !isEmpty(coll);
      + +
    • + + +
    • +
      + +
      + +
      +

      gtLen :: Int-> Iterable<a> -> bool
      checks if the length of the collection in greater than a limt

      + +
      + +
      export const gtLen = (lim = 0) => coll => len(coll) > lim;
      + +
    • + + +
    • +
      + +
      + +
      +

      eqLen ::Int-> Iterable<a> -> bool
      checks if the length of the collection in equal to a limt

      + +
      + +
      export const eqLen = (lim = 0) => coll => len(coll) === lim;
      + +
    • + + +
    • +
      + +
      + +
      +

      ltLen :: Int-> Iterable<a> -> bool
      checks if the length of the collection in less than a limt

      + +
      + +
      export const ltLen = (lim = 0) => coll => len(coll) < lim;
      + +
    • + + +
    • +
      + +
      + +
      +

      single :: Iterable<a> -> bool
      checks if the array has only a single element

      + +
      + +
      export const single = coll => eqLen(1)(coll);
      + +
    • + + +
    • +
      + +
      + +
      +

      sameSize :: Iterable<a> -> Iterable<a> -> bool
      checks length of two collections for equality

      + +
      + +
      export const sameSize = a => b => len(a) === len(b);
      + +
    • + +
    +
    + + diff --git a/docs/manipulate.html b/docs/manipulate.html index d0290f7..dda822b 100644 --- a/docs/manipulate.html +++ b/docs/manipulate.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -112,7 +122,8 @@

    manipulate.js

    -

    addMap :: Map[{k:v}] -> k -> v -> Map[{k:v}]
    adds an element to a Map;

    +

    addMap :: Map[{k:v}] -> k -> v -> Map[{k:v}] +adds an element to a Map;

    @@ -127,7 +138,8 @@

    manipulate.js

    -

    addMapTuple :: Map[{k:v}] -> (...{k:v}) -> Map[{k:v}]
    adds multiple [k,v] pairs to an iterable;

    +

    addMapTuple :: Map[{k:v}] -> (...{k:v}) -> Map[{k:v}] +adds multiple [k,v] pairs to an iterable;

    @@ -142,7 +154,8 @@

    manipulate.js

    -

    addSet :: Set[a] -> (...a) -> Set[a]
    adds multiple elements to a Set;

    +

    addSet :: Set[a] -> (...a) -> Set[a] +adds multiple elements to a Set;

    @@ -157,7 +170,8 @@

    manipulate.js

    -

    removeSet :: Set[a] -> (...a) -> Set[a]
    removes multiple elements from a Set;

    +

    removeSet :: Set[a] -> (...a) -> Set[a] +removes multiple elements from a Set;

    @@ -172,7 +186,8 @@

    manipulate.js

    -

    removeMap :: Map[{k:v}] -> (...k) -> Map[{k:v}]
    removes multiple keys from a Map;

    +

    removeMap :: Map[{k:v}] -> (...k) -> Map[{k:v}] +removes multiple keys from a Map;

    @@ -187,7 +202,8 @@

    manipulate.js

    -

    removeMapTuple :: Map[{k:v}] -> (...{k:v}) -> Map[{k:v}]
    removes multiple [k,v] pairs from a Map;

    +

    removeMapTuple :: Map[{k:v}] -> (...{k:v}) -> Map[{k:v}] +removes multiple [k,v] pairs from a Map;

    @@ -203,7 +219,8 @@

    manipulate.js

    -

    popElem :: Iterable<a> -> a -> Iterable<a>
    removes the last element from an iterable;

    +

    popElem :: Iterable<a> -> a -> Iterable<a> +removes the last element from an iterable;

    @@ -218,7 +235,8 @@

    manipulate.js

    -

    popFirst :: Iterable<a> -> a -> Iterable<a>
    removes the first element from an iterable;

    +

    popFirst :: Iterable<a> -> a -> Iterable<a> +removes the first element from an iterable;

    diff --git a/docs/match.html b/docs/match.html new file mode 100644 index 0000000..fd02af1 --- /dev/null +++ b/docs/match.html @@ -0,0 +1,156 @@ + + + + + match.js + + + + + +
    +
    + + + +
      + +
    • +
      +

      match.js

      +
      +
    • + + + +
    • +
      + +
      + +
      + +
      + +
      import { filtBy, mapTo,some, } from './array';
      +import { has, } from './has';
      +import { append, } from './group';
      +
      +export const identity = x => x;
      +
      +const id = identity;
      +const { assign, } = Object;
      +
      +export const matches = (mFn = id) => a => b => mFn(a) === mFn(b);
      +
      +export const matchBin = (mFn = id) => (a,b) => matches(mFn)(a)(b);
      +
      +export const xMatches = (mFn = id) => a => b => !matches(mFn)(a)(b);
      +
      +export const xMatchBin = (mFn = id) => (a,b) => !matches(mFn)(a)(b);
      +
      +export const mergeMatch = (mFn = id) => b => a => 
      +  matches(mFn)(a)(b) ? assign({},a,b) : a;
      +  
      +export const swapMatch = (mFn = id) => b => a => matches(mFn)(a)(b) ? b : a;
      +
      +export const matchMap = (mFn = id) => coll => mapTo(mFn)(coll);
      +
      +export const hasMatch = (mFn = id) => a => coll => has(matchMap(mFn)(coll))(mFn(a));
      +
      +export const xHasMatch = (mFn = id) => a => coll => !hasMatch(mFn)(a)(coll); 
      +
      +export const addUniq = (mFn = id) => a => coll => 
      +  some(coll)(matches(mFn)(a)) ? coll : append(coll)(a);
      +
      +export const dropMatch = (mFn = id) => a => coll =>
      +  filtBy(xMatches(mFn)(a))(coll);
      +
      +export const replaceMatch = (mFn = id) => a => coll =>
      +  mapTo(swapMatch(mFn)(a))(coll);
      +
      +export const updateMatch = (mFn = id) => a => coll =>
      +  mapTo(mergeMatch(mFn)(a))(coll);
      + +
    • + +
    +
    + + diff --git a/docs/reducers.html b/docs/reducers.html index e1b9057..9367f91 100644 --- a/docs/reducers.html +++ b/docs/reducers.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js diff --git a/docs/spread.html b/docs/spread.html index da06498..3ece64c 100644 --- a/docs/spread.html +++ b/docs/spread.html @@ -60,11 +60,21 @@ + + length.js + + + manipulate.js + + match.js + + + reducers.js @@ -110,7 +120,8 @@

    spread.js

    -

    spread :: Iterable<a> -> Iterable<a>
    returns an Iterable of the collections default iterator

    +

    spread :: Iterable<a> -> Iterable<a> +returns an Iterable of the collections default iterator

    @@ -125,7 +136,8 @@

    spread.js

    -

    spreadK :: Iterable<a> -> Iterable<a>
    returns an Iterable of the collections keys

    +

    spreadK :: Iterable<a> -> Iterable<a> +returns an Iterable of the collections keys

    @@ -140,7 +152,8 @@

    spread.js

    -

    spreadV :: Iterable<a> -> Iterable<a>
    returns an Iterable of the collections values

    +

    spreadV :: Iterable<a> -> Iterable<a> +returns an Iterable of the collections values

    @@ -155,7 +168,8 @@

    spread.js

    -

    spreadE :: Iterable<a> -> Iterable<a>
    returns an Iterable of the collections entries

    +

    spreadE :: Iterable<a> -> Iterable<a> +returns an Iterable of the collections entries

    @@ -170,7 +184,8 @@

    spread.js

    -

    spreadKV :: Iterable<a> -> Iterable<a>
    returns an Iterable of the collections entries

    +

    spreadKV :: Iterable<a> -> Iterable<a> +returns an Iterable of the collections entries

    diff --git a/src/spread.js b/src/spread.js index 39635bb..1b460a2 100644 --- a/src/spread.js +++ b/src/spread.js @@ -1,23 +1,23 @@ // requires [iterify](iterable.html) import { iterify, } from './iterable'; -// **spread** `:: Iterable -> Iterable` +// **spread** `:: Iterable -> Iterable` // returns an Iterable of the collections default iterator export const spread = (coll = []) => [ ...iterify(coll), ]; -// **spreadK** `:: Iterable -> Iterable` +// **spreadK** `:: Iterable -> Iterable` // returns an Iterable of the collections keys export const spreadK = (coll = []) => spread(iterify(coll).keys()); -// **spreadV** `:: Iterable -> Iterable` +// **spreadV** `:: Iterable -> Iterable` // returns an Iterable of the collections values export const spreadV = (coll = []) => spread(iterify(coll).values()); -// **spreadE** `:: Iterable -> Iterable` +// **spreadE** `:: Iterable -> Iterable` // returns an Iterable of the collections entries export const spreadE = (coll = []) => spread(iterify(coll).entries()); -// **spreadKV** `:: Iterable -> Iterable` +// **spreadKV** `:: Iterable -> Iterable` // returns an Iterable of the collections entries export const spreadKV = spreadE;