Skip to content

Commit

Permalink
Added flat
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Feb 13, 2018
1 parent f8680b5 commit 7c5abc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/partial.lenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,13 @@ export function compose() {
}
}

export function flat() {
const r = [flatten]
for (let i = 0, n = arguments.length; i < n; ++i)
r.push(arguments[i], flatten)
return r
}

// Recursing

export function lazy(o2o) {
Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe('arities', () => {
find: 1,
findWith: 1,
first: undefined,
flat: 0,
flatten: 4,
foldTraversalLens: 2,
foldl: 4,
Expand Down Expand Up @@ -1705,6 +1706,21 @@ describe('L.pointer', () => {
})
})

describe('L.flat', () => {
testEq(
`L.modify(
L.flat(
'a',
'b',
'c'
),
R.negate,
[{a: [[{b: {c: 1}}], [{b: [{c: 2}]}]]}, {a: {b: {c: [[[3]]]}}}]
)`,
[{a: [[{b: {c: -1}}], [{b: [{c: -2}]}]]}, {a: {b: {c: [[[-3]]]}}}]
)
})

if (process.env.NODE_ENV !== 'production') {
describe('debug', () => {
testThrows(`X.set(-1, 0, 0)`)
Expand Down
1 change: 1 addition & 0 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const traverse = T.fn(
// Nesting

export const compose = T.fnVarN(0, T_optic, T_optic)
export const flat = T.fnVarN(0, T_optic, T_optic)

// Recursing

Expand Down

0 comments on commit 7c5abc9

Please sign in to comment.