Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active January 22, 2018 18:16
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 barneycarroll/0111cb142989f9f645878939e18803f7 to your computer and use it in GitHub Desktop.
Save barneycarroll/0111cb142989f9f645878939e18803f7 to your computer and use it in GitHub Desktop.
Patchinko's overloaded module re-written in terse yet spacious expressions (source: https://github.com/barneycarroll/patchinko/blob/master/overloaded.js)
export default function O(a){
return (
arguments.length == 1
?
typeof a != 'function'
?
new O(a => O(b, a))
:
this instanceof O
?
(
this.apply = b => a(b),
this
)
:
new O(b)
:
[...arguments].reduce(({}, b) => (
Object.entries(b).forEach(([key, val]) => (
val == O
?
delete a[key]
:
a[key] =
val instanceof O
?
val.apply(a[key])
:
val
)),
a
))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment