Code Monkey home page Code Monkey logo

Comments (5)

nkrkv avatar nkrkv commented on June 4, 2024

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.

Gipphe avatar Gipphe commented on June 4, 2024

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.

nkrkv avatar nkrkv commented on June 4, 2024

Oh, thanks. For the strictness and definite return value type exception is fine I think.

from hm-def.

Gipphe avatar Gipphe commented on June 4, 2024

My thoughts exactly.

from hm-def.

davidchambers avatar davidchambers commented on June 4, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.