ephetic / functional Goto Github PK
View Code? Open in Web Editor NEWES6 Functional Helpers
ES6 Functional Helpers
Custom predicate would already work, but it might be nice to specify multiple shapes/basic-predicates like m([m.OR(Number, String), fn])
12
import { matcher as m } from '@ephetic/functional'
const secondIsNumber = m(
[ [m, Number], (a,b) => console.log(`${b} is a Number`)],
[ [m, Array], (a,b) => console.log(`${b} is an Array`)],
[ m, (a,b) => console.log(`${b} is not a Number or Array`)]
)
secondIsNumber('asdf', 2) // 2 is a Number
secondIsNumber(2, {}) // [object Object] is an Array
secondIsNumber(2, 'asdf') // asdf is an Array
For Array conditions (i.e. argument checking), look into only passing as many arguments to fn
as the length of the argument pattern, i.e. fn.apply(null, args.slice(0, cond.length)
.
This might be useful for when m functions are passed as callbacks to things that pass extra arguments. Wait, no; it's patterns will have to match those arguments. How about when the m function is given a callback as fn
that expects an unknownish number of args. Yeah, maybe.
If nothing else, it would make it more predictable.
[]
is matched against anything rather than only matching a zero-argument call
e.g. m([[Integer, Integer], () => console.log('int')])(1,2)
Not sure they even work. Once verified, improve the README.md notes on Arrays.
Since arrays are used to represent a parameter pattern, a literal array must be wrapped in an object {foo: [11,22,33]}
. However, it would be nice to make sure the [head, ...rest]
semantics work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.