function toArray(children) {
    return children == null ? [] : Array.isArray(children) ? children : [children]
}

export const Children = {
    only(children) {
        return (children && children[0]) || null;
    },
    count(children) {
        return (children && children.length) || 0;
    },
    forEach(children, callback, context) {
        toArray(children).forEach(callback, context);
    },
    map(children, callback, context) {
        return toArray(children).map(callback, context);
    },
    toArray
};
