-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39c81c9
commit d8be103
Showing
8 changed files
with
244 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import spread, { spreadK, spreadKV, spreadV, } from './spread'; | ||
// requires [cast](cast.html), and [spread](spread.html) | ||
import { asMap, } from './cast'; | ||
import spread, { spreadK, spreadKV, spreadV, } from './spread'; | ||
|
||
// **get** `:: iter[{k:v}] -> k -> v` | ||
// retrieves a value stored at a key from a collection | ||
export const get = c => k => asMap(c).get(k); | ||
|
||
// **fromIndex** `:: [a] -> number -> a` | ||
// returns the value stored at an array position | ||
export const fromIndex = (c = new Set) => i => spread(c).slice(i, i + 1).shift(); | ||
|
||
// **first** `:: iter[a] -> a` | ||
// returns the first element of an iterable | ||
export const first = (c = []) => spread(c).shift(); | ||
|
||
// **last** `:: iter[a] -> a` | ||
// returns the last element of an iterable | ||
export const last = (c = []) => spread(c).pop(); | ||
|
||
// **firstK** `:: iter[{k:v}] -> k` | ||
// returns the first key of an iterable | ||
export const firstK = (c = []) => first(spreadK(c)); | ||
|
||
// **lastK** `:: iter[{k:v}] -> k` | ||
// returns the last key of an iterable | ||
export const lastK = (c = []) => last(spreadK(c)); | ||
|
||
// **firstV** `:: iter[a] -> a` | ||
// returns the first value of an iterable | ||
export const firstV = (c = []) => first(spreadV(c)); | ||
export const lastV = (c = []) => last(spreadV(c)); | ||
|
||
export const fromIndex = (c = new Set) => i => spread(c).slice(i, i + 1).shift(); | ||
// **lastV** `:: iter[a] -> a -> [a]` | ||
// returns the last value of an iterable | ||
export const lastV = (c = []) => last(spreadV(c)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
// requires [spread](spread.html) | ||
import spread from './spread'; | ||
|
||
// **map** `:: iter[a] -> (a->b) -> [b]` | ||
// returns an array of the return values of a | ||
// function called on each element of an iterable | ||
export const map = coll => fn => spread(coll).map(fn); | ||
|
||
// **reduce** `:: iter[a] -> ((a->b), b) -> b` | ||
// returns the accumulated value of a function | ||
// called on each element of an iterable | ||
export const reduce = coll => (fn, init) => spread(coll).reduce(fn, init); | ||
|
||
// **filter** `:: iter[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); | ||
|
||
// **every** `:: iter[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); | ||
|
||
// **some** `:: iter[a] -> (a->b) -> [b]` | ||
// checks if any element of an iterable returns true for a given function | ||
export const some = coll => fn => spread(coll).some(fn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// requires [spread](spread.html) | ||
import spread, { spreadKV, } from './spread'; | ||
|
||
// **asArray** `:: iter -> array` | ||
// **asArray** `:: iter[a] -> [a]` | ||
// returns an array of the collections default iterator | ||
export const asArray = c => spread(c); | ||
|
||
// **asSet** `:: iter -> set` | ||
// **asSet** `:: iter[a] -> Set[a]` | ||
// returns an array of the collections default iterator | ||
export const asSet = c => new Set(spread(c)); | ||
|
||
// **asMap** `:: iter -> map` | ||
// **asMap** `:: iter[a] -> Map[a]` | ||
// returns an array of the collections default iterator | ||
export const asMap = c => new Map(spreadKV(c)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters