Skip to content

Commit

Permalink
Upgraded to use Partial Lenses v14
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Aug 14, 2018
1 parent ce3d04b commit c8f6419
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 154 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 2.0.0

To reduce implementation complexity the following combinators no longer allow
the predicates or functions passed to them to be asynchronous:

* `V.ifElse`
* `V.choose`
* `V.cases`
* `V.casesOf`

The functions that are allowed to be asynchronous are now marked in the document
with the `async` keyword.

## 0.3.8

Fixed `V.run` contract.
Expand Down
106 changes: 57 additions & 49 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
],
"homepage": "https://github.com/calmm-js/partial.lenses.validation",
"dependencies": {
"infestines": "^0.4.9",
"partial.lenses": "^13.12.0"
"infestines": "^0.4.10",
"partial.lenses": "^14.0.0"
},
"ignore": ["*", "!*.md", "!dist/*"]
}
109 changes: 58 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "partial.lenses.validation",
"version": "1.0.4",
"version": "2.0.0",
"description": "Partial Lenses Validation is a JavaScript library for validating and transforming data",
"module": "dist/partial.lenses.validation.es.js",
"main": "dist/partial.lenses.validation.cjs.js",
Expand Down Expand Up @@ -35,8 +35,8 @@
},
"homepage": "https://github.com/calmm-js/partial.lenses.validation#readme",
"dependencies": {
"infestines": "^0.4.9",
"partial.lenses": "^13.12.0"
"infestines": "^0.4.10",
"partial.lenses": "^14.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^4.0.0",
"sprintf-js": "^1.1.1",
"uglify-js": "^3.4.6",
"uglify-js": "^3.4.7",
"watch-run": "^1.2.5"
}
}
94 changes: 50 additions & 44 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,6 @@ export const remove = acceptAs(undefined)

//

const casesOfDefault = I.always(reject)
const casesOfCase = (p, o, r) => (y, j) => (x, i, M, xi2yM) =>
M.chain(
b =>
b
? o(x, i, M, xi2yM)
: undefined !== b || raised === unique
? r(y, j)(x, i, M, xi2yM)
: rejectRaisedOr(M, x),
p(y, j)
)

//

const ruleBinOp = op =>
I.curryN(
2,
Expand Down Expand Up @@ -389,14 +375,10 @@ export const props = propsOr(reject)

export const choose = xi2r => (
(xi2r = protect(xi2r)),
copyName(
(x, i, M, xi2yM) =>
M.chain(
r => (r ? toRule(r)(x, i, M, xi2yM) : rejectRaisedOr(M, x)),
xi2r(x, i)
),
xi2r
)
copyName((x, i, M, xi2yM) => {
const r = xi2r(x, i)
return r ? toRule(r)(x, i, M, xi2yM) : rejectRaisedOr(M, x)
}, xi2r)
)

// Conditional
Expand All @@ -414,31 +396,55 @@ export const ifElse = I.curry(function ifElse(p, c, a) {
c = toRule(c)
a = toRule(a)
return function ifElse(x, i, M, xi2yM) {
return M.chain(
b =>
b
? c(x, i, M, xi2yM)
: undefined !== b || raised === unique
? a(x, i, M, xi2yM)
: rejectRaisedOr(M, x),
p(x, i)
)
const b = p(x, i)
return b
? c(x, i, M, xi2yM)
: undefined !== b || raised === unique
? a(x, i, M, xi2yM)
: rejectRaisedOr(M, x)
}
})

export function casesOf(lens) {
lens = L.toFunction(lens)
let n = arguments.length
let op = casesOfDefault
while (--n) {
const c = arguments[n]
op =
I.length(c) !== 1
? casesOfCase(protect(c[0]), toRule(c[1]), op)
: I.always(toRule(c[0]))
export function casesOf(of) {
of = L.toFunction(of)

let n = arguments.length - 1
if (!n) return reject

let def = arguments[n]
if (def.length === 1) {
--n
def = toRule(def[0])
} else {
def = reject
}

const ps = Array(n)
const os = Array(n + 1)
for (let i = 0; i < n; ++i) {
const c = arguments[i + 1]
ps[i] = protect(c[0])
os[i] = toRule(c[1])
}
os[n] = def

return function casesOf(x, i, M, xi2yM) {
return lens(x, i, L.Constant, op)(x, i, M, xi2yM)
let min = n
const r = of(x, i, L.Select, (y, j) => {
for (let i = 0; i < min; ++i) {
const b = ps[i](y, j)
if (b) {
min = i
if (i === 0) return 0
else break
} else if (undefined === b && raised !== unique) {
const r = raised
raised = unique
return M.of(rejected(r))
}
}
})
return r ? r : os[min](x, i, M, xi2yM)
}
}

Expand All @@ -461,5 +467,5 @@ export const promote = (...cs) =>
export const upgrades = (...cs) =>
lazy(rec => cases.apply(null, cs.map(upgradesCase(rec))))

export const upgradesOf = (lens, ...cs) =>
lazy(rec => casesOf.apply(null, [lens].concat(cs.map(upgradesCase(rec)))))
export const upgradesOf = (of, ...cs) =>
lazy(rec => casesOf.apply(null, [of].concat(cs.map(upgradesCase(rec)))))
Loading

0 comments on commit c8f6419

Please sign in to comment.