Last active
July 16, 2018 21:02
-
-
Save VitorLuizC/b74289dfa94e1138147c1fd383c087f4 to your computer and use it in GitHub Desktop.
Collection library
This file contains hidden or 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
| import * as object from './object' | |
| export const toObject = (collection) => | |
| [ ...collection ].reduce(object.increase, {}) |
This file contains hidden or 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
| export const tail = <T> (array: Array<T>): T => array[array.length - 1]; | |
| export const exceptTail = <T> (array: Array<T>): Array<T> => array.slice(0, array.length - 1); | |
| /** | |
| * Convert collection to PT-BR statement. | |
| */ | |
| type toStatementΛ = <T> (value: T) => string; | |
| const toStatement = <T> ( | |
| array: Array<T>, | |
| λ: toStatementΛ = (value) => String(value) | |
| ): string => | |
| array.length === 0 ? '' : | |
| array.length === 1 ? λ(array[0]) | |
| : exceptTail(array).map(λ).join(', ') + ' e ' + λ(tail(array)); |
This file contains hidden or 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
| export const increase = (object, [ property, value ]) => ({ | |
| ...object, | |
| [property]: value | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment