improve concat
This commit is contained in:
parent
e13371fa4a
commit
13cf60abdb
2 changed files with 9 additions and 3 deletions
|
@ -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'],
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue