Skip to content

Instantly share code, notes, and snippets.

@jgoux
Last active December 20, 2016 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoux/554e7683c8b1311832aec50b04cc7a55 to your computer and use it in GitHub Desktop.
Save jgoux/554e7683c8b1311832aec50b04cc7a55 to your computer and use it in GitHub Desktop.
R.lens* and R.cond are best friends!
import R from 'ramda'
export const getFormData = R.pipe(
(form) => [...(new FormData(form)).entries()],
R.reduce(
(a, [k, v]) => {
const kL = R.lensProp(k)
return R.cond([
[R.pipe(R.view(kL), R.isNil), R.set(kL, v)],
[R.pipe(R.view(kL), R.isArrayLike), R.over(kL, R.append(v))],
[R.T, R.over(kL, (x) => [x, v])]
])(a)
},
{}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment