Add concat function (#2640)

This commit is contained in:
Aya Morisawa 2018-09-06 21:31:15 +09:00 committed by syuilo
parent f428372869
commit 3cace734c7
4 changed files with 14 additions and 8 deletions

View File

@ -85,6 +85,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import { host, copyright } from '../../../config'; import { host, copyright } from '../../../config';
import { concat } from '../../../../../prelude/array';
export default Vue.extend({ export default Vue.extend({
data() { data() {
@ -119,8 +120,8 @@ export default Vue.extend({
(this as any).api('notes/local-timeline', { (this as any).api('notes/local-timeline', {
fileType: image, fileType: image,
limit: 6 limit: 6
}).then(notes => { }).then((notes: any[]) => {
const files = [].concat(...notes.map(n => n.files)); const files = concat(notes.map((n: any): any[] => n.files));
this.photos = files.filter(f => image.includes(f.type)).slice(0, 6); this.photos = files.filter(f => image.includes(f.type)).slice(0, 6);
}); });
}, },

View File

@ -40,6 +40,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import { apiUrl, copyright, host } from '../../../config'; import { apiUrl, copyright, host } from '../../../config';
import { concat } from '../../../../../prelude/array';
export default Vue.extend({ export default Vue.extend({
data() { data() {
@ -79,8 +80,8 @@ export default Vue.extend({
(this as any).api('notes/local-timeline', { (this as any).api('notes/local-timeline', {
fileType: image, fileType: image,
limit: 6 limit: 6
}).then(notes => { }).then((notes: any[]) => {
const files = [].concat(...notes.map(n => n.files)); const files = concat(notes.map((n: any): any[] => n.files));
this.photos = files.filter(f => image.includes(f.type)).slice(0, 6); this.photos = files.filter(f => image.includes(f.type)).slice(0, 6);
}); });
} }

View File

@ -1,4 +1,4 @@
import { count, countIf } from "../../prelude/array"; import { count, concat } from "../../prelude/array";
// MISSKEY REVERSI ENGINE // MISSKEY REVERSI ENGINE
@ -286,7 +286,7 @@ export default class Reversi {
} }
}; };
return [].concat(...diffVectors.map(effectsInLine)); return concat(diffVectors.map(effectsInLine));
} }
/** /**

View File

@ -6,6 +6,10 @@ export function count<T>(x: T, xs: T[]): number {
return countIf(y => x === y, xs); return countIf(y => x === y, xs);
} }
export function intersperse<T>(sep: T, xs: T[]): T[] { export function concat<T>(xss: T[][]): T[] {
return [].concat(...xs.map(x => [sep, x])).slice(1); return ([] as T[]).concat(...xss);
}
export function intersperse<T>(sep: T, xs: T[]): T[] {
return concat(xs.map(x => [sep, x])).slice(1);
} }