import React, { ReactElement } from 'react'

interface ListProps<T> {
  children: any,
  data: Array<T>,
  className?: string
}

function List(props: ListProps<any>) : ReactElement {
  let fns = props.children
  
  if (!(props.children instanceof Array)) {
    fns = [props.children]
  }
  
  return (
    <div className={props.className}>
      {
        (fns as Array<any>).map(Fn => (
          typeof Fn === 'function' ?
            props.data.map((obj, i) => Fn(obj, i)) :
            Fn
        ))
      }
    </div>
  )
}

export default List