Comments (5)
Why did Lodash ever appeared among the dependencies? cond
and fromPairs
were initially provided by Ramda.
β Ramda is not safe, Sanctuary is better, letβs get rid of Ramda in favor of Sanctuary. That was a good idea for #8
But Sanctuary misses a few functions from Ramda. They are quite trivial and are re-implemented on the top of signature.js
:
// isEmpty :: Foldable f => f a -> Boolean
const isEmpty = xs => xs.length === 0;
// propEq :: String -> a -> StrMap a -> Boolean
const propEq = prop => val => obj => obj[prop] === val;
// indexBy :: (StrMap a -> String) -> Array (StrMap a) -> StrMap (StrMap a)
const indexBy = memoize
(f => S.reduce
(xs => x => S.insert (f (x)) (x) (xs))
({}));
The missing cond
and fromPairs
look trivial too and IMO it is better to just re-implement them the same way and drop the lodash.*
dependencies altogether.
PRs are welcome.
from hm-def.
I originally replaced them in a (somewhat misguided) effort to get rid of Ramda. At the time, I didn't bother to just write them myself, but, looking at them now, I see they aren't complicated at all. So I wrote them just now.
// fromPairs :: Array (Array2 String a) -> StrMap a
const fromPairs = S.reduce
(acc => curr => S.insert (curr[0]) (curr[1]) (acc))
({});
// cond :: Array (Array2 (a -> Boolean) (a -> b)) -> a -> b
const cond = conds => x => {
const c = conds.find (y => y[0] (x));
if (c !== undefined) {
return c[1] (x);
}
throw new Error (`No predicate was satisfied for ${x}`);
};
Unsure whether cond
should return undefined
or throw if none of the cases match though. Thoughts?
from hm-def.
Oh, thanks. For the strictness and definite return value type exception is fine I think.
from hm-def.
My thoughts exactly.
from hm-def.
This signature is misleading:
// isEmpty :: Foldable f => f a -> Boolean const isEmpty = xs => xs.length === 0;
One of the following would be accurate:
// isEmpty :: { length :: Number } -> Boolean
const isEmpty = xs => xs.length === 0;
// isEmpty :: Foldable f => f a -> Boolean
const isEmpty = xs => S.size (xs) === 0;
// isEmpty :: Monoid a => a -> Boolean
const isEmpty = xs => S.equals (xs) (S.empty (xs.constructor));
from hm-def.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hm-def.