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 interface HasLevel { | |
| level: number; | |
| } | |
| export type TreeNode<T> = T & { | |
| children: TreeNode<T>[]; | |
| }; | |
| // 「状態を受け取り新しい状態を返す関数」を変換の最小単位として扱う。 | |
| type Action<S> = (state: S) => S; |
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 interface HasLevel { | |
| level: number; | |
| } | |
| export type TreeNode<T> = T & { | |
| children: TreeNode<T>[]; | |
| }; | |
| type Action<S> = (state: S) => S; |
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 interface HasLevel { | |
| level: number; | |
| } | |
| /** | |
| * ツリー構造のノードを表す。元の型 T に children 配列を追加する。 | |
| */ |
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 interface HasLevel { | |
| level: number; | |
| } | |
| export type TreeNode<T> = T & { | |
| children: TreeNode<T>[]; | |
| }; | |
| export const flatToMatrix = <T extends HasLevel>(flatItems: T[]): TreeNode<T>[] => { | |
| if (flatItems.length === 0) { |