Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lists

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lists

A library of higher-order functions modeled after Haskell's Data.List module

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-29.41%
Maintainers
1
Weekly downloads
 
Created
Source

[ l [ i [ s ] t ] s ]

Full Version | Homepage

Lists is a library of JavaScript higher-order functions for working with arrays and strings. The library was inspired by Haskell's Data.List module by the powerful people over at The University of Glasgow. You can view the original source here. You could then scroll through each function closely and see a purposefully similar correlation between the Haskell implementation and this implementation.

Pass functions to functions to functions to solve complex problems. Most of the functions featured in Lists produce new arrays, to reinforce the paradigm of stateless programming.

Disclaimer: Almost all of these functions are naive recursive definitions. The idea behind this library is to maximize problem-solving expressivity. This library provides an alternative toolbox by which to solve problems. This library should be sufficient for most projects but remember to monitor your heap memory space in the case of excessive function calls.


Install


Components


Type Signature Legend

  • arr | [] : Array
  • obj | {} : Object
  • str : String
  • num : Number
  • f : Function
  • x : variable

A{ 1. } Function number

B{ tail } Function name

C{ arr|str -> [x] } Pseudo type signature

tail : arr|str -> [x]

  • Takes an Array of variables or String and produces an array of variables ([x]).

map : [x] -> f -> [x]

  • Takes an Array of variables and a function and produces an array of variables.

Basic Functions


List Transformations


Reducing Lists (folds)


Building Lists


Sublists

  • take : num -> [x]|str -> [x]
  • drop : num -> [x]|str -> [x]
  • splitAt : num -> [x]|str -> [[x],[x]]
  • takeWhile : f -> [x]|str -> [x]
  • dropWhile : f -> [x]|str -> [x]
  • span : arr|str -> f -> [[x], [x]|str]
  • break : arr|str -> f -> [[x], [x]|str]
  • stripPrefix : [num]|str -> [num]|str -> [num]|[str]
  • group : Eq a => [a] -> [[a]]
  • inits : [a] -> [[a]]
  • tails : [a] -> [[a]]
  • isPrefixOf : Eq a => [a] -> [a] -> Bool
  • isSuffixOf : Eq a => [a] -> [a] -> Bool
  • isInfixOf : Eq a => [a] -> [a] -> Bool

Searching Lists

  • elem : Eq a => a -> [a] -> Bool
  • notElem : Eq a => a -> [a] -> Bool
  • lookup : Eq a => a -> [(a, b)] -> Maybe b
  • find : (a -> Bool) -> [a] -> Maybe a
  • filter : (a -> Bool) -> [a] -> [a]
  • partition : (a -> Bool) -> [a] -> ([a], [a])

Indexing Lists

  • bang : [a] -> Int -> a
  • elemIndex : Eq a => a -> [a] -> Maybe Int
  • elemIndices : Eq a => a -> [a] -> [Int]
  • findIndex : (a -> Bool) -> [a] -> Maybe Int
  • findIndices : (a -> Bool) -> [a] -> [Int]

Zipping and Unzipping Lists

  • zip || unzip : [[a],[b],..,[n]] -> [[a,b,..,n]]
  • zipWith : (a -> b -> c) -> [[a],[b],..,[n]] -> [c,..,n]

Special Lists

  • lines : String -> [String]
  • words : String -> [String]
  • unlines : [String] -> String
  • unwords : [String] -> String
  • nub : Eq a => [a] -> [a]
  • delete : Eq a => a -> [a] -> [a]
  • difference || diff : Eq a => [a] -> [a] -> [a]
  • union : Eq a => [a] -> [a] -> [a]
  • intersect : Eq a => [a] -> [a] -> [a]
  • sort : Ord a => [a] -> [a]
  • insert : Ord a => a -> [a] -> [a]

Generalized Functions

  • nubBy : (a -> a -> Bool) -> [a] -> [a]
  • deleteBy : (a -> a -> Bool) -> a -> [a] -> [a]
  • deleteFirstsBy : (a -> a -> Bool) -> [a] -> [a] -> [a]
  • unionBy : (a -> a -> Bool) -> [a] -> [a] -> [a]
  • intersectBy : (a -> a -> Bool) -> [a] -> [a] -> [a]
  • groupBy : (a -> a -> Bool) -> [a] -> [[a]]
  • sortBy : (a -> a -> Ordering) -> [a] -> [a]
  • insertBy : (a -> a -> Ordering) -> a -> [a] -> [a]
  • maximumBy : (a -> a -> Ordering) -> [a] -> a
  • minimumBy : (a -> a -> Ordering) -> [a] -> a

Extra Functional Utilities

  • genericExcludeChar :
  • forEach || each :
  • keys :
  • enumeration || enum :
  • composeL || pipe :
  • composeR || sequence :
  • partial || part :
  • flip :
  • compare :
  • GT,LT,EQ :
  • bubbleSort :
  • mergeSort :

### append : arr|str -> arr|str|num -> [x]|str ------ **Description**: A prefix-style Array.prototype.concat wrapper.

Signature Definition: Give arg 1 an Array or a String; Give arg 2 an Array or a String or a Number; Get an Array of variables or String.

Example Usage:

lists.append([1],[2]); /* [1,2] */ 
lists.append([1],2); /* [1,2] */ 
lists.append('a','b'); /* 'ab' */

### head : arr|str -> x ------ **Description**: Retreive the first element of an Array or a String.

Signature Definition: Give arg 1 an Array or a String; Get a variable.

Example Usage:

lists.head([1,2]); /* 1 */ 
lists.head([[1,2],[3,4]]); /* [1,2]  */ 
lists.head('ab'); /* 'a' */

### last : arr|str -> x ------ **Description**: Retreive the last element of an Array or a String.

Signature Definition: Give arg 1 an Array or a String; Get a variable.

Example Usage:

lists.last([1,2]); /* 2 */ 
lists.last([[1,2],[3,4]]); /* [3,4] */ 
lists.last('ab'); /* 'b' */

### init : arr|str -> [x] ------ **Description**: Retreive all elements except the last of an Array or a String.

Signature Definition: Give arg 1 an Array or a String; Get an Array of variables.

Example Usage:

lists.init([1,2,3]); /* [1,2] */ 
lists.init([[1,2],[3,4],[5,6]]); /* [[1,2],[3,4]]  */ 
lists.init('abc'); /* ['a','b'] */

### tail : arr|str -> [x] ------ **Description**: Retreive all elements except the first of an Array or a String.

Signature Definition: Give arg 1 an Array or a String; Get an Array of variables.

Example Usage:

lists.tail([1,2,3]); /* [2,3] */ 
lists.tail([[1,2],[3,4],[5,6]]); /* [[3,4],[5,6]]  */ 
lists.tail('abc'); /* ['b','c'] */

### nil : arr|str -> boolean ------ **Description**: Test if an Array or String is empty.

Signature Definition: Give arg 1 an Array or a String; Get a boolean.

Example Usage:

lists.nil(null); /* true */ 
lists.nil([]); /* true */ 
lists.nil(''); /* true */ 
lists.nil('a'); /* false */ 
lists.nil([1]); /* false */

### map : [x] -> f -> [x] ------ **Description**: Array returned by applying f to each element of [x]

Signature Definition: Give arg 1 an Array or a String; Give arg 2 a Function; Get an Array of variables.

Example Usage:

lists.map([1,2,3], function(x) { return x*2 }); /* [2,4,6] */
lists.map('abc', function(str) { return str.toUpperCase() }); /* ["A","B","C"] */
lists.map([{'S': 1}, {'u': 2}, {'p': 3}], function(obj) {
  return lists.flatten(lists.keys(obj))
}); /* ["S", "u", "p"] */

### rev : [x] -> [x] ------ **Description**: Array returned by reversing the order of each element.

Signature Definition: Give arg 1 an Array or a String; Get an Array of variables.

Example Usage:

lists.rev([1,2,3]); /* [3,2,1] */
lists.rev('abc'); /* ['c','b','a'] */
lists.rev([[2],[3]]) /* [[3],[2]] */

### intersperse : x -> [x] -> arr|str ------ **Description**: Array or String returned by interspersing a given separator between elements of a given Array.

Signature Definition: Give arg 1 a variable; Give arg 2 an Array of variables; Get an Array of variables.

Example Usage:

lists.intersperse(1,[5,5,5]); /* [5,1,5,1,5] */
lists.intersperse([1,2],[[6],[6]]); /* [[6],[1,2],[6]] */
lists.intersperse('b','ac'); /* 'abc' */
lists.intersperse({b:2},[{a:1},{b:3}]); /* [{a:1},{b:2},{c:3}] */

### intercalate : [x] -> [[x]] -> [x] ------ **Description**: Array returned by flattening the result of interspersing an Array of varaibles into an Array of Arrays.

Signature Definition: Give arg 1 an Array of variables; Give arg 2 an Array of Arrays of variables; Get an Array of variables.

Example Usage:

lists.intercalate([1],[[5],[5],[5]]); /* = lists.flatten(lists.intersperse([1],[[5],[5],[5]])) // [5,1,5,1,5] */
lists.intercalate(["abc"],[["efg"],["qrs"]]) /* ["efg", "abc", "qrs"] */
lists.intercalate([{a:1}],[[{b:1}],[{c:2}]]); /* [{b:1},{a:1},{c:2}] */

### transpose : [[x]] -> [[x]] ------ **Description**: Array returned by transposing rows and columns of given arguments.

Signature Definition: Give arg 1 an Array of Arrays of variables; Get an Array of Arrays of variables.

Example Usage:

lists.transpose([[1,2,4],[3,4,4]]) /* [[1,3],[2,4],[4,4]] */
lists.transpose([["a","b","c"],["a","b","c"]]) /* [["a","a"],["b","b"],["c","c"]] */

### subsequences : [x] -> [[x]] ------ **Description**: Array of Arrays of all subsequences of a given arguement.

Signature Definition: Give arg 1 an Array of variables; Get an Array of Arrays of variables.

Example Usage:

lists.subsequences('ab') /* [[],['a'],['b'],['ab']] */
lists.subsequences([1,2,3]) /* [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] */

### permutations : [x]|str -> [[x]]|[str] ------ **Description**: Array of Arrays or Array of Strings returned by getting all permutations of a given arguement.

Signature Definition: Give arg 1 an Array of variables or a String; Get an Array of Arrays of variables or an Array of Strings respectively.

Example Usage:

lists.permutations('abc') /* ["abc","acb","bac","bca","cab","cba"] */
lists.permutations([1,2,3]) /* [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] */

### foldl : x -> [x]|str -> f -> x ------ **Description**: Variable returned reducing left to right by applying a binary operator function (f) on a starting variable (x), known as the accumulator, and an Array of variables or String

Signature Definition: Give arg 1 a starting variable (usually a left identity of the binary operator); Give arg 2 an Array of variables or a String; Give arg 3 a function (binary operator); Get a variable.

Example Usage:

reverse = lists.foldl('','abc',function(x,y){ return y.concat(x); }); /* "cba" */
sum = lists.foldl(0,[1,2,3],function(x,y){ return x+y; }); /* 6 */
lists.foldl([], [[1,2],[3,4]], function(x,y) {return x.concat(y) }) /* [1,2,3,4] */

### foldl1 : [x]|str -> f -> x ------ **Description**: Variant of foldl without a starting variable (The accumulator begins with the 0th index of the passed Array or String). Use with non-empty Arrays or Strings.

Signature Definition: Give arg 1 an Array of variables or a String; Give arg 2 a function (binary operator); Get a variable.

Example Usage:

lists.foldl1('abc',function(x,y){ return x.concat(y).toUpperCase() }) /* "ABC" */
lists.foldl1([1,2,3],function(x,y){ return x+y }) /* 6 */

### foldr : x -> [x]|str -> f -> x ------ **Description**: Variable returned reducing right to left by applying a binary operator function (f) on a starting variable (x), known as the accumulator, and an Array of variables or String

Signature Definition: Give arg 1 a starting variable (usually a right identity of the binary operator); Give arg 2 an Array of variables or a String; Give arg 3 a function (binary operator); Get a variable.

Example Usage:

lists.foldr(0,[1,2,3,4],function(x,y){ return x-y; }) /* -2 */
lists.foldr([],[[1,2],[3,4],[5,6]],function(x,y){ 
  return lists.rev(x).concat(y); 
}); /* [4,3,1,2,5,6] */

### foldr1 : [x]|str -> f -> x ------ **Description**: Variant of foldr without a starting variable (The accumulator begins with the 0th index of the passed Array or String). Use with non-empty Arrays or Strings.

Signature Definition: Give arg 1 an Array of variables or a String; Give arg 2 a function (binary operator); Get a variable.

Example Usage:

lists.foldr1([1,2,3],function(x,y){ return x - y }) /* 3 */
lists.foldr1('aabbcc',function(x,y){ return x=='a'? x=y : x.concat(y)}) /* "bbcc" */

### flatten || concat : [[x]]|[str] -> [x]|str ------ **Description**: Flatten an Array of Arrays or an Array of String into an Array of variables or String respectively.

Signature Definition: Give arg 1 an Array of Arrays of variables or a String; Get an Array of variables or a String

Example Usage:

lists.flatten(['abc']); /* 'abc' */
lists.flatten([[1,2],[3,4]]) /* [1,2,3,4] */

### concatMap : [x]|str -> f -> [x]|str ------ **Description**: Array of variables or String returned by mapping a function over an Array of variables or String and flattening the result

Signature Definition: Give arg 1 an Array of variables or a String; Give arg 2 a function that produces an Array of variables or String; Get an Array of variables or a String

Example Usage:

lists.concatMap(['bang','bang'], function(x){ return x+'!'}) /* "bang!bang!" */
lists.concatMap([1,2,3],function(x){ return [[x*2,x/2]] }) /* [[2,0.5],[4,1],[6,1.5]] */
lists.concatMap([{a:1},{b:2}], function(x){
  x.prop = 'hi';  
  return [x]
}); /* [{a:1,prop:"hi"},{b:2,prop:"hi"}]*/

### and : [boolean] -> boolean ------ **Description**: Boolean returned by the conjunction of an Array of booleans. True if all booleans are true. False if one or more booleans is false.

Signature Definition: Give arg 1 an Array of booleans. Get a boolean.

Example Usage:

lists.and([5>1,5>2,5>3]) /* true */
lists.and([5>1,false,5>3]) /* false */

### or : [boolean] -> boolean ------ **Description**: Boolean returned by the disjunction of an Array of booleans. True if at least one boolean is true. False if all booleans are false.

Signature Definition: Give arg 1 an Array of booleans. Get a boolean.

Example Usage:

lists.or([5<1,5<2,5>3]) /* true */
lists.or([5<1,5<2,5<3]) /* false */

### any : [x]|str -> f -> boolean ------ **Description**: Boolean returned by applying a predicate function to each element in an Array of variables or String. True if at least one f(x) is true. False if all f(x) are false.

Signature Definition: Give arg 1 an Array of variables or String; Give arg 2 a predicate function to be applied to each element of arg 1; Get a boolean.

Example Usage:

lists.any([1,2,3],function(x) { return x < .5}) /* false */
lists.any('abc',function(x) { return x == 'b'}) /* true */

### all : [x]|str -> f -> boolean ------ **Description**: Boolean returned by applying a predicate function to each element in an Array of variables or String. True if all f(x) are true. False if any f(x) are false.

Signature Definition: Give arg 1 an Array of variables or String; Give arg 2 a predicate function to be applied to each element of arg 1; Get a boolean.

Example Usage:

lists.all('abc', function(x){ return x==x.toUpperCase() }) /* false */
lists.all([2,4], function(x) { return x > 3 }) /* false */
lists.all([2,4], function(x) { return x%2==0 }) /* true */

### sum : [num] -> num ------ **Description**: Number returned by summing the numbers of an Array together.

Signature Definition: Give arg 1 an Array of Numbers; Get a number.

Example Usage:

lists.sum([2,4,6]) /* 12 */
lists.sum([.2,.4,.6]) /* 1.2000000000000002 */

### product : [num] -> num ------ **Description**: Number returned by computing the product of the numbers of an Array.

Signature Definition: Give arg 1 an Array of Numbers; Get a number.

Example Usage:

lists.product([2,4,6]) /* 48 */
lists.product([.2,.4,.6]) /* 0.04800000000000001 */

### maximum : [num] -> num ------ **Description**: Maximum number returned from numbers of an Array.

Signature Definition: Give arg 1 an Array of Numbers; Get a number.

Example Usage:

lists.maximum([2,4,6]) /* 6 */
lists.maximum([.2,.4,.6]) /* .6 */

### minimum : [num] -> num ------ **Description**: Minimum number returned from numbers of an Array.

Signature Definition: Give arg 1 an Array of Numbers; Get a number.

Example Usage:

lists.minimum([2,4,6]) /* 2 */
lists.minimum([.2,.4,.6]) /* .2 */

### maxList : [[x]] -> [x] ------ **Description**: Array of variables with the maximum length returned from an Array of Arrays of variables.

Signature Definition: Give arg 1 an Array of Arrays of variables; Get an Array of variables.

Example Usage:

lists.maxList([[1],[2,3]]) /* [2,3] */
lists.maxList([[1,2],[3]]) /* [1,2] */

### minList : [[x]] -> [x] ------ **Description**: Array of variables with the minimum length returned from an Array of Arrays of variables.

Signature Definition: Give arg 1 an Array of Arrays of variables; Get an Array of variables.

Example Usage:

lists.minList([[],[1]]) /* [] */
lists.minList([[1,2],[3]]) /* [3] */

### scanl : x -> [x]|str -> f -> [x] ------ **Description**: Array of variables returned building left to right, starting with the accumulator (x) by applying a binary operator function (f) on a starting variable (x) and an Array of variables or String

Signature Definition: Give arg 1 a starting variable; Give arg 2 an Array of variables or a String; Give arg 3 a function (binary operator); Get an Array of variables.

Example Usage:

lists.scanl('.','abc',function(x,y){return x + y}) /* [".",".a",".ab",".abc"] */
lists.scanl(0,[1,2,3],function(x,y){return x + y}) /* [0,1,3,6] */

### scanr : x -> [x]|str -> f -> [x] ------ **Description**: Array of variables returned building right to left, starting with the accumulator (x) by applying a binary operator function (f) on a starting variable (x) and an Array of variables or String

Signature Definition: Give arg 1 a starting variable; Give arg 2 an Array of variables or a String; Give arg 3 a function (binary operator); Get an Array of variables.

Example Usage:

lists.scanr('.','abc',function(x,y){return x + y}) /* ["abc.","bc.","c.","."] */
lists.scanr(0,[1,2,3],function(x,y){return x + y}) /* [6,5,3,0] */

### mapAccumL : x -> [x]|str -> f -> [x, [x]] ------ **Description**: Builds an Array containing a accumulator (x) and the result of applying f to the supplied accumulator and each element of the supplied Array from left to right.

Signature Definition: Give arg 1 a starting variable (accumulator); Give arg 2 an Array of variables or a String; Give arg 3 a function; Get an Array of variable followed by Array of variables.

Example Usage:

lists.mapAccumL(5, [2,4,8], function(x,y){ return [x+y,x*y]}) /* [19, [10,28,88]]*/
lists.mapAccumL(5, [2,4,8], function(x,y){ return [y,y]}) /* [8, [2,4,8]] */
lists.mapAccumL(5, [5,5,5], function(x,y){ return [x,x]}) /* [5, [5,5,5]] */

### mapAccumR : x -> [x]|str -> f -> [x, [x]] ------ **Description**: Builds an Array containing a accumulator (x) and the result of applying f to the supplied accumulator and each element of the supplied Array from right to left.

Signature Definition: Give arg 1 a starting variable (accumulator); Give arg 2 an Array of variables or a String; Give arg 3 a function; Get an Array of variable followed by Array of variables.

Example Usage:

lists.mapAccumR(5, [2,4,8], function(x,y){ return [x+y,x*y]}) /* [19, [34,52,40]]*/
lists.mapAccumR(5, [2,4,8], function(x,y){ return [y,y]}) /* [2, [2,4,8]] */
lists.mapAccumR(5, [5,5,5], function(x,y){ return [x,x]}) /* [5, [5,5,5]] */

### iterate : x -> num -> f -> [x] ------ **Description**: Builds an Array containing the successive application of f to the previous result of f(x) until the stop (num) reaches 0.

Signature Definition: Give arg 1 a variable; Give arg 2 a number; Give arg 3 a function; Get an Array of variables.

Example Usage:

lists.iterate('a',3,function(ch){return ch+'b'}) /* ["a","ab","abb"] */
lists.iterate([1,2],3,function(xs){return lists.intersperse(6,xs)}) /* [[1,2],[1,6,2],[1,6,6,6,2]] */
lists.iterate(2,4,function(x){ return x*x }) /* [2,4,16,256] */

### replicate : x -> num -> [x] ------ **Description**: Builds an Array containing replications of x until the stop (num) reaches 0.

Signature Definition: Give arg 1 a variable; Give arg 2 a number; Get an Array of variables.

Example Usage:

lists.replicate(5,5) /* [5,5,5,5,5] */
lists.replicate([1,2],2) /* [[1,2],[1,2]] */
lists.replicate({a:1},2) /* [{a:1},{a:2}] */

### cycle : [x]|str -> num -> [x]|str ------ **Description**: Builds an Array containing replications of flattened [x]|String until the stop (num) reaches 0.

Signature Definition: Give arg 1 an Array of variables; Give arg 2 a number; Get an Array of variables.

Example Usage:

lists.cycle('abc',3) /* "abcabcabc" */
lists.cycle([1,2],2) /* [1,2,1,2] */

### unfold : f -> f -> f -> x -> [x]|str ------ **Description**: Builds an Array from a seed value. Arg 1 is the predicate function. If the predicate fails, return an empty Array, otherwise concatenate the result of Arg 2 (f) applied to Arg 4 (x) to the recursive call of unfold calling Arg 3 (f) to Arg 4 (x). This is a corecursive anamorphism.

Signature Definition: Give arg 1 an function (predicate); Give arg 2 a function; Give arg 3 a function; Give arg 4 a variable (seed).

Example Usage:

function chop8(xs){ 
  return l.unfold(l.nil,l.part(l.take,8,_),l.part(l.drop,8,_),xs) 
}
chop8([1,2,3,4,5,6,7,8,9]) /* [[1,2,3,4,5,6,7,8],[9]] */

function unfoldMap(xs,f) { 
  return lists.unfold(
    lists.nil, 
    lists.part(lists.pipe(f,lists.head),_), 
    lists.part(lists.tail,_), 
    xs)
}
unfoldMap([1,2],function(x){ return x * 2 }) /* [2,4] */

### take : num -> [x]|str -> [x] ------ **Description**: Array of variables returned by taking the first n (num) elements from [x] or String.

Signature Definition: Give arg 1 a number; Give arg 2 an Array of variables or String; Get an Array of variables.

Example Usage:

lists.take(2,[1,2,3]) /* [1,2] */
lists.take(2,'abc') /* ["a","b"] */

### drop : num -> [x]|str -> [x] ------ **Description**: Array of variables returned by dropping the first n (num) elements from [x] or String.

Signature Definition: Give arg 1 a number; Give arg 2 an Array of variables or String; Get an Array of variables.

Example Usage:

lists.drop(2,[1,2,3]) /* [3] */
lists.drop(2,'abc') /* ["c"] */

### splitAt : num -> [x]|str -> [[x],[x]] ------ **Description**: Array of two Arrays returned. The first Array contains the first n elements of the supplied Array of variables or String. The second contains the rest.

Signature Definition: Give arg 1 a number; Give arg 2 an Array of variables or String; Get an Array of two Arrays of variables.

Example Usage:

lists.splitAt(2,'abc') /* [['a','b'],['c']] */
lists.splitAt(2,[1,2,3]) /* [[1,2],[3]] */

### takeWhile : f -> [x]|str -> [x] ------ **Description**: Array of variables returned by taking elements from [x]|String that satisfy a supplied predicate function until that predicate function is unsatisfied.

Signature Definition: Give arg 1 a function; Give arg 2 an Array of variables or String; Get an Array of variables.

Example Usage:

lists.takeWhile([1,2,3,1], function(x){ return x < 3 }) /* [1,2] */
lists.takeWhile([1], function(x){ return x < 2 }) /* [1] */
lists.takeWhile('aabc', function(x){ return x =='a' }) /* ["a","a"] */

### dropWhile : f -> [x]|str -> [x] ------ **Description**: Array of variables returned by dropping elements from [x]|String that satisfy a supplied predicate function until that predicate function is unsatisfied.

Signature Definition: Give arg 1 a function; Give arg 2 an Array of variables or String; Get an Array of variables.

Example Usage:

lists.dropWhile([1,2,3,4], function(x){ return x < 3 }) /* [3,4] */
lists.dropWhile([1], function(x){ return x < 2 }) /* [2] */
lists.dropWhile('aabc', function(x){ return x =='a' }) /* ["b","c"] */

### span : arr|str -> f -> [[x], [x]|str] ------ **Description**: An Array of Array of variables and Array of variables or String (psuedo-tuple) is returned. The first element is the longest prefix of an Array of variables or String that satisfy a predicate function f. The second element is the rest of the list.

Signature Definition: Give arg 1 an Array of variables or String; Give arg 2 a function; Get an Array of Array of variables and Array of variables or String (psuedo-tuple).

Example Usage:

lists.span([1,2,3,4], function(x){return x < 3}) /* [[1,2],[3,4]] */
lists.span("abcde", function(x){return x == "a"}) /* [["a"],["b","c","d","e"]] */
lists.span([{a:2},{a:2},{b:2}], function(x){return x.a==2}) /* [[{a:2},{a:2}],[{b:2}]] */

### break : arr|str -> f -> [[x], [x]|str] ------ **Description**: An Array of Array of variables and Array of variables or String (psuedo-tuple) is returned. The first element is the longest prefix of an Array of variables or String that do not satisfy a predicate function f. The second element is the rest of the list.

Signature Definition: Give arg 1 an Array of variables or String; Give arg 2 a function; Get an Array of Array of variables and Array of variables or String (psuedo-tuple).

Example Usage:

lists.break([1,2,3,4], function(x){return x < 3}) /* [[],[1,2,3,4]] */
lists.break("abcde", function(x){return x == "a"}) /* [[],"abcde"] */
lists.break([{a:2},{a:2},{b:2}], function(x){return x.a==2}) /* [[],[{a:2},{a:2},{b:2}]] */

### stripPrefix : [num]|str -> [num]|str -> [num]|[str] ------ **Description**: Argument 1 is the prefix. Argument 2 is the target. The arguments must be of the same type. This function drops the prefix from the target and returns the representation as an Array of Numbers or an Array of Strings.

Signature Definition: Give arg 1 an Array of Numbers or String; Give arg 2 an Array of Numbers or String; Get an Array of Numbers or an Array of Strings.

Example Usage:

lists.stripPrefix("abc","abcabce") /* ["a","b","c","e"] */
lists.stripPrefix([1,2],[1,2,3,4]) /* [3,4] */

Keywords

FAQs

Package last updated on 07 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc