WARNING
potential security vulnerabilities in dependencies
project is not maintained, use ramdajs
Open documentation! ;3
yarn add linqable.ts
ornpm i linqable.ts
<scriptsrc="https://cdn.jsdelivr.net/npm/linqable.ts@1.7.18/lib/web/linq.min.js"></script>See Changelog
Browser:
<head><scriptsrc="https://cdn.jsdelivr.net/npm/linqable.ts@1.7.18/lib/web/linq.min.js"></script></head><!-- ... --><script>[2,4].Sum()// -> 6</script>Node:
import"linqable.ts";console.log([3,5].Sum());Use Advanced & Base Linqable:
import{AdvancedLinqable,BaseLinqable}from"linqable.ts";console.log(newBaseLinqable([3,5]).Sum());console.log(newAdvancedLinqable([3,5]).Acquire());yarn build- You are great! 💫
- TypeScript 3.0 or above (in global)
- AVA 1.0.0-beta.8 or above (in global)
yarn test- ava write test-report to screen
Advanced API
Advanced API
Transposes the rows of a sequence into columns.
letarray=[["Nola","Myse"],["Ruq"],["Dufna","Nygglatho","Kumesh"]];/* ... */array.Transpose();// result ->[['Nola','Ruq','Dufna',],['Myse','Nygglatho',],['Kumesh',],]Returns a sequence containing the values resulting from invoking (in order) each function in the source sequence of functions.
letarray=[()=>"Chtholly",()=>"Ithea",()=>1+1,()=>!true]/* ... */array.Evaluate();// => ["Chtholly", "Ithea", 2, false]Ensures that a source sequence of objects are all acquired successfully. If the acquisition of any one fails then those successfully acquired till that point are delete
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Acquire();// => success // => [{name: "Chtholly Nola", age: 17}, { name: "Ithea Myse", age: 18 }]array.Acquire();// => fail // => [] // => throwCompletely consumes the given sequence. This method uses immediate execution, and doesn't store any data during execution
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Consume();Batches the source sequence into sized buckets.
letarray=[{name: "Chtholly Nola"},{name: "Nephren Ruq"},{name: "Almaria Dufna"},{name: "Ithea Myse"}]/* ... */array.Batch(2);// => [[{name: "Chtholly Nola"}, {name: "Nephren Ruq"}],[{name: "Almaria Dufna"}, {name: "Ithea Myse"}]]// Returns an array with 2 arrays 😏Returns the maxima (maximal elements) of the given sequence, based on the given projection.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.MaxBy(x=>x.age)// => { name: "Ithea Myse", age: 18 }Returns the minima (minimal elements) of the given sequence, based on the given projection.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.MinBy(x=>x.age)// => {name: "Chtholly Nola", age: 17}Excludes elements from a sequence starting at a given index
letarray=["CO2","Ir2O","C2O3","NH3","C2H6","H2C03"]/* ... */array.Exclude(1,2)// -> ["CO2", "NH3", "C2H6", "H2C03"]Flattens a sequence containing arbitrarily-nested sequences.
letarray=["CO2",["C2O3",["NH3",127.4],241,"H2C03"]/* ... */array.Flatten()// -> ["CO2", "C2O3", "NH3", 127.4, 241, "H2C03"]Returns a sequence resulting from applying a function to each element in the source sequence and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element
letarray=["atom","core","neutron"];/* ... */array.Pairwise((x,y)=>`${x} contains ${y}`)// -> ["atom contains core", "core contains neutron"]Executes the given action on each element in the source sequence and yields it
letarray=[{name: 'neutron',lifetime: 880},{name: "proton",lifetime: Infinity}]/* ... */array.Pipe(x=>x.lifetime++);array.Where(x=>x.name=="neutron").lifetime// -> 881Produces a projection of a sequence by evaluating pairs of elements separated by a negative offset.
letarray=[0,1,2,3,4];/* ... */array.Lag(/*step*/2,/*defaultValue*/0,(a,b)=>{return{A: a,B: b};})//returned -> [{"A":0,"B":0},{"A":1,"B":0},{"A":2,"B":0},{"A":3,"B":1},{"A":4,"B":2}]Standard API
Standard API
Returns the first element of a sequence. (Predicate Support)
letarray=[{formula: "CeO2",MolarMass: 172.115},{formula: "O",MolarMass: 15.999}];/* ... */array.First()// => {formula: "CeO2", MolarMass: 172.115 }letdefaultValue={formula: "H",MollarMass: 14.1}[].FirstOrDefault(null,defaultValue)// => {formula: "H", MollarMass: 14.1 }Returns the last element of a sequence. (Predicate Support)
letarray=[{formula: "CeO2",MolarMass: 172.115},{formula: "O",MolarMass: 15.999}];/* ... */array.Last()// => {formula: "O", MolarMass: 15.999 }letdefaultValue={formula: "H",MollarMass: 14.1}[].LastOrDefault(null,defaultValue)// => {formula: "H", MollarMass: 14.1 }Projects each element of a sequence into a new form.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Nephren Ruq",age: 17}]/* ... */array.Select(x=>x.name.split(' ').First())// => [{name: "Chtholly"}, {"Nephren"}]Filters a sequence of values based on a predicate.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Nephren Ruq",age: 17},{name: "Almaria Dufna",age: 19},{name: "Ithea Myse",age: 18}]/* ... */// where adult only 🙈array.Where(x=>x.age>=18)// => [ {name: "Almaria Dufna", age: 19}, {name: "Ithea Myse", age: 18}]Determines whether any element of a sequence exists or satisfies a condition.
letarray=[{name: "Chtholly Nola",IsDead: true},{name: "Nephren Ruq",IsDead: false},{name: "Almaria Dufna",IsDead: true},{name: "Ithea Myse",IsDead: true}]/* ... */array.Any(x=>x.IsDead)// => truearray.Where(x=>!x.IsDead).Any(x=>x.IsDead)// => falseDetermines whether all elements of a sequence satisfy a condition.
letarray=[{name: "Chtholly Nola",IsDead: true},{name: "Nephren Ruq",IsDead: false},{name: "Almaria Dufna",IsDead: true},{name: "Ithea Myse",IsDead: true}]/* ... */array.All(x=>x.IsDead)// => falsearray.Where(x=>x.IsDead).All(x=>x.IsDead)// => trueComputes the sum of the sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.
letarray1=[1,2,3];letarray2=[{num: 15},{num: 10}];/* ... */array1.Sum()// => 6array2.Sum(x=>x.num)// => 25Gets a value indicating whether this array contains no elemets.
letarray1=[];letarray2=["Cobalt","Mithril"];/* ... */array1.IsEmpty()// => truearray2.IsEmpty()// => falseInvokes a transform function on each element of a sequence and returns the minimum number value.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Min(x=>x.age)// => 17Invokes a transform function on each element of a sequence and returns the maximum number value.
letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Max(x=>x.age)// => 18Returns a specified number of contiguous elements from the start of a sequence.
letarray=["Cobalt","Mithril","Adamantium"];/* ... */array.Take(2)// => ["Cobalt","Mithril"]Sorts the elements of a sequence in a particular direction (ascending, descending) according to a key.
letarray=[4,2,7,3,0,6];/* ... */array.OrderBy();// => [0, 2, 3, 4, 6, 7];Supports primitives, including Date.
To compare other objects,
you need to implement interface IComparer (TypeScript)
or implement function [Compare(y) : number]
As well support Descending.
Inverts the order of the elements in a sequence.
letarray=[{name: "Chtholly Nola"},{name: "Nephren Ruq"},{name: "Almaria Dufna"},{name: "Ithea Myse"}]/* ... */array.Reverse()// => [{name: "Ithea Myse"},{name: "Almaria Dufna"},{name: "Nephren Ruq"},{name: "Chtholly Nola"}]Returns distinct elements from a sequence by using the default equality comparer to compare values.
letarray1=["Alkaloid","Protein","Chlorophyll","Alkaloid"];/* ... */array1.Distinct()// => ["Alkaloid", "Protein", "Chlorophyll"]Produces the set union of two sequences.
letarray1=["Alkaloid","Protein","Chlorophyll","Alkaloid"];letarray2=["Uranium","Iridium","Iridium","Plutonium"];/* ... */array1.Union(array2)// => ["Alkaloid", "Protein", "Chlorophyll", "Uranium", "Iridium", "Plutonium"]Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
letwoman=["Chtholly","Nephren"];letman=["Willem","Willem"];woman.Zip(man,(w,m)=>`${w} love ${m}`)// => ["Chtholly love Willem", "Nephren love Willem"]Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
letarray=[{synthesis: "Nuclear"},{synthesis: "Thermonuclear"}]array.Single()// => Throw Error/* ... */array.SingleOrDefault({synthesis: "none"})// => return default value // => {synthesis: "none"}/* ... */array=[{synthesis: "Nuclear"}];/* ... */array.Single()// => {synthesis: "Nuclear"}Road Map
- First
- FirstOrDefault
- Last
- LastOrDefault
- Select
- SelectMany
- Where
- Any
- All
- Sum
- Take
- TakeWhile
- Min & Max
- MinBy & MaxBy
- IsDefault
- OrderBy
- Range
- Reverse
- Single
- SingleOrDefault
- SkipWhile
- ThenBy
- ThenByDescending
- ToArray
- Union
- Zip
- Aggregate
- Count
- Average
- Append
- Contains
- DefaultIfEmpty
- Distinct
- Except
- GroupBy
- GroupJoin
- Join
- Acquire
- AggregateRight
- Assert
- AssertCount
- AtLeast
- AtMost
Backsert- Batch
Cartesian- Choose (Deferred typescript 3)
- Concat
- Consume
- CountBetween & CountBy & CountDown & CompareCount
- EndsWith
- EquiZip
- DistinctBy
- Exactly
- ExceptBy
- Exclude
- Evaluate
FallbackIfEmpty- FillBackward & FillForward
- Flatten
Fold- FullGroupJoin
- FullJoin
- Generate & GenerateByIndex
- GroupAdjacent
- Index
- Insert
- Interleave
- Lag
- Lead
- LeftJoin
- Move
- OrderedMerge
- Pad & PadStart
- Pairwise
- PartialSort & PartialSortBy
- Partition
- Permutations
- Pipe
- Prepend
PreScan- Random & RandomDouble & RandomSubset
Rank & RankBy- Repeat
- RightJoin
- RunLengthEncode
- Scan & ScanRight
- Segment
Sequence- Shuffle
- SkipLast & SkipUntil
- Slice
- SortedMerge
- Split
- StartsWith
- Subsets
- TagFirstLast
Transpose- TakeEvery & TakeLast & TakeUntil
ZipLongest & ZipShortest

