diff --git a/src/function.js b/src/function.js index 23c6436..fd9263f 100644 --- a/src/function.js +++ b/src/function.js @@ -1,6 +1,6 @@ import { curry, curryN } from './curry.js' import { dispatch } from './fantasy-land.js' -import { concat as iconcat, iter } from './list.js' +import { concat as iconcat, isIterable, iter } from './list.js' /** @import { Fn, Morphism, InferredMorphism, Predicate } from './types.js' */ @@ -18,8 +18,13 @@ export const id = x => x export const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x) export const concat = dispatch(['fantasy-land/concat', 'concat'], - (b, a) => iconcat(iter(a), iter(b)) -) + (b, a) => { + if (isIterable(a) || isIterable(b)) { + return iconcat(iter(a), iter(b)) + } else { + return a.concat(b) + } + }) export const compose = dispatch(['fantasy-land/compose', 'compose'], /** diff --git a/src/type.js b/src/type.js index 660e4ff..113b074 100644 --- a/src/type.js +++ b/src/type.js @@ -25,4 +25,5 @@ export const is = curry( export const isFn = x => type(x) === 'function' export const isArray = Array.isArray +export const isIterable = x => x != null ? typeof x[Symbol.iterator] === 'function' : false