General:
Other sequence/iterable packages:
- TC39 Proposal
- OCaml
- F#
- .net Enumerable
- Rust
- Python Itertools
- Itertools for Javascript
- More LINQ
- Immutable.js Seq
- Haskell List
- Racket
- F#
concatis flatten andappendis just 1 - OCaml
concatis flatten andappendis just 1 - Haskell
concatis flatten and+is just 1 - JavaScript arrays
concatis one or more, and separateflatfunction - .net Enumerable
concatis just one - Rust is
flattenfor many andchainfor just one
Ok, sticking with concat for JavaScript familiarity, even though it conflicts with sequences in other functional languages. But adding synonym of append for since it goes nicely with prepend.
Sometimes it is useful to have the index of an item when performing a computation. This can be accomplished by calling the indexed function before calling the function that needs the index. This is how it is done in F#. Rust has an enumerate function. So indexed versions aren't as important as they would be with non-lazy array functions where adding the index regenerates the entire array. Indexed versions are useful in a couple cases: (1) where developers expect it from experience with JavaScript array functions, (2) when the user is likely going to NOT want the index after they have performed some kind of transformation, because then they have to first call indexed, and then after the transformation, do a map to get rid of it. This is the case with filter.
There are many useful "set-based" functions like union, intersect, distinct, except, countBy that could be built if we had a...
type set<'a, 'b> = {
empty: unit => 'b,
has: ('b, 'a) => bool,
add: ('b, 'a) => 'b,
}Also it is useful to summarize the entire data set with a groupBy, do join, etc.
I got a lazy distinctBy working where the user provides a comparison function ('a,'a)=>int. The code relies on Belt.Set under-the-hood. Belt.Set relies on a hardcoded module for each type you want to put in the set, so I made it a type unknown and did some Obj.magic to make it work. My implementation was hardcoded to a specific set and equality test. Better performance might be possible using hash equality or the built-in JavaScript Set. Also if the function is meant to be lazy, an immutable set is helpful.
map, filter, take, drop, flatMap, reduce, toArray, forEach, some, every, find
from (iterator)
isEmpty, uncons, length, iter, fold_left, iteri, fold_lefti, for_all, exists, find, find_map, compare, empty, return, cons, init, unfold, equal, repeat, forever, iterate, cycle, map, mapi, filter, filter_map, take, drop, take_while, drop_while, memoize, append, concat, flat_map, zip, sorted_merge, scan, product, concat_map, interleave, map2, once, onceWith
iter2, fold_left2, for_all2, exists2, group, map_product, unzip, partition_map, partition, ints
allPairs, append, cache, choose, chunkBySize, collect, compareWith, concat, delay, empty, exists, filter, fold, forAll, head, indexed, init, initInfinite, isEmpty, iter, iteri, last, length, map, map2, map3, mapFold, mapi, maxBy, minBy, ofArray, ofList, pairwise, pick, replicate, reduce, rev, scan, singleton, skip, skipWhile, sortWith, tail, takeWhile, toArray, toList, truncate, tryExactlyOne, tryFind, tryHead, tryLast, tryPick, unfold, where, windowed, zip, zip3
average, averageBy, cast, contains, countBy, distinctBy, exactlyOne, except, exists2, findBack, findIndex, fold2, foldBack, foldBack2, forAll2, groupBy, insertAt, insertManyAt, item (nth), iter2, iteri2, mapFoldBack, mapi2, max, min, permute, readonly, reduceBack, removeAt, removeManyAt, scanBack, sort, sortBy, sortByDescending, sortDescending, sortWith, splitInto, sum, sumBy, transpose, take (throws like takeExactly), tryFindBack, tryFindIndex, tryFindIndexBack, tryItem, updateAt
Interesting that take is really takeAtMost and skip is really skipAtMost while for F# these throw exceptions if there aren't enough elements.
More tools need to look!
all, any, array_chunks, chain, cmp_by, count, cycle, enumerate, eq_by, filter, filter_map, find, find_map, flat_map, flatten, fold, for_each, inspect, intersperse, intersperseWith, is_sorted_by, last, map, max_by, min_by, partial_cmp_by, product, reduce, rev, scan, skip, skip_while, take, take_while, zip
advance_by, cloned, cmp, collect, collect_into, copied, eq, fuse, ge, gt, partitioned, try_fold, is_sorted, is_sorted_by_key, le, lt, map_while, max, min, ne, next_chunk, nth, partial_cmp, partition, partition_in_place, peekable, position, rPosition, size_hint, step_by, sum, try_collect, try_find, try_fold, try_for_each, try_reduce, unzip, some kind of remainder ability
cycle, repeat, accumulate, chain, dropwhile, filterfalse, pairwise, takewhile, zip_longest, product, permutations, combinations
count, compress, groupby, islice, starmap, tee, combinations_with_replacement, recipes: all_equal, subslices
range, drop, dropWhile, enumerate, filter, flat, flatMap, interpose, map, prepend, take, takeWhile, tap, window, batch, collate, concat, join, zip, deepEqual, every, find, findBest, first, isEmpty, reduce, size, some, takeLast, fork, arrayFrom, forEach, toString, toArray, firstHighest, firstLowest, repeat, reverse, roundRobin, isSorted
range (with step), objectEntries, objectKeys, objectValues, append (one value), distinct, interposeSeq, slice, takeSorted, bisect, split, splitGroups, splitOn, splitWhen, compress, joinWith, firstOr, includes, includesAny, many async flavors, startsWith, startsWithAny, str, takeLastOr, objectFrom, toObject, lastHighest, lastLowest, zipAll, windowAhead, windowBehind
Video series on many of these Not investigated everything yet
takeUntil, dropUntil, consume, fallbackIfEmpty
endsWith, flatten (recursive), tagFirstLast, toMap, toObject
Not investigated everything yet https://immutable-js.com/docs/v4.3.0/Seq/
https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-List.html
prefix and drop do not throw.
append, head, last, tail, init (all elements except for the last), uncons, length, map, reverse, intersperse, intercalate, transpose, subsequences (combinations), permutations, foldl, foldll (no initial value), foldr, foldrl, concat, concatMap, and, or, any, all, sum, product, maximum, minimum, scanl, scanr, mapAccumL (is this like the F# one?), iterate, repeat, replicate, cycle, unfold, take, drop, splitAt, takeWhile, dropWhile, dropWhileEnd, span, break, stripPrefix, group, inits, tails, isPrefixOf, isSuffixOf, isInfixOf, isSubsequenceOf, find, filter, partition, elemIndex, elemIndices, findIndex, findIndices, zip, zip3, etc. zipWith, zipWith3, etc. unzip, lines, union, intersect, sortOn, insertBy,
https://docs.racket-lang.org/seq/index.html
deduplicate generates a list not a sequence
by (every nth element), rest, init (all but the last)