marpple / partial.js Goto Github PK
View Code? Open in Web Editor NEW(deprecated)
License: MIT License
(deprecated)
License: MIT License
toArray로 유사 배열(arguments)등을 변경하더라도, 테스트 프레임워크에서 배열로 인식하지 않아서 테스트에서 fail 합니다. (mocha+expect에서 확인하였는데 제 기억으로는 jest+expect도 동일할 듯합니다)
아마다 키 값으로 __mr이 있는 등 일반 배열과는 다른 형태로 리턴이 되어서 그럴 듯 합니다. toArray에서 리턴 전에 Array.prototype.slice.call을 이용해서 실제 배열로 변환하고 있는것을 확인하였는데, 어디서 문제인지 모르겠습니다.
여러 방법으로 해결해보려던 중 위 이미지와 같이 .mr로 만든 멀티리턴값은 toArray를 통해 일반 배열로 변환 되고 테스트를 통과하는 것을 확인하였고(expect(.toArray(_.mr(15, 5, 50))).toEqual([15, 5, 50])=> 통과함) _.go를 이용하여 생성한 파이프라인의 결과값인 res는 toArray를 통해 일반 배열로 변환되지 않고 테스트 실패하는 것을 확인하였습니다.
책의 예제가(코드 5-29) 작동하지 않습니다.
partial.js코드를 살펴보니, 소스로 제공된 partial.js와 npm에 올라온 partial.js의 소스코드가 다릅니다.
파라메터로 숫자가 넘어오면 함수를 리턴하게 되어있어서, 즉시 실행이 되지 않고 있습니다.
관련해서 확인 부탁드립니다.
_.all(10, 5, [
function(a, b) { return a + b },
function(a, b) { return a - b },
function(a, b) { return a * b }]);
// 결과:
// arguments { 0: 15, 1: 5, 2: 50, _mr: true }
_.spread(10, 5, [
function(a) { return a * a },
function(b) { return b * b }]);
// 결과:
// arguments { 0: 100, 1: 25, _mr: true }
partial.js의 소스 부분
.all = .All = function(arg) {
var fns = [], count = -1;
if (.is_number(arg))
return function f() { return ++count < arg ? (fns.push(.pipe(arguments)), f) : _.all2.apply(this, [to_mr(arguments)].concat(fns)) };
fns = .last(arguments);
if (.is_array(fns)) return _.all2.apply(this, [to_mr(arg)].concat(fns));
fns = _.to_array(arguments);
return function() { return _.all2.apply(this, [to_mr(arguments)].concat(fns)) }
};
좋은 라이브러리 감사합니다. 타입스크립트 프로젝트에서는 사용하기 어려운데 타입스크립트에 대한 지원 계획이 있는지 궁금합니다 :)
안녕하세요? pipe 내에서 extend 를 사용하는 방법에 대해 궁금한게 있습니다.
아래처럼 aPipeFn 을 정의한 경우
const aPipeFn = _.pipe(
_.pick([ 'pick1', 'pick2' ]),
_.extend({ ex1: 'e1', ex2: 'e2' }),
)
aPipeFn({pick1: 'p1', pick2: 'p2', pick3: 'p3'}) 의 결과로 {pick1: 'p1', pick2: 'p2', ex1: 'e1', ex2: 'e2'} 이 나오길 기대했지만 에러가 발생하고 있습니다.
const aPipeFn = _.pipe(
_.pick([ 'pick1', 'pick2' ]),
data => _.extend(data, { ex1: 'e1', ex2: 'e2' }),
)
aPipeFn 을 위와 같이 정의했을 때 제가 원하는 결과가 나오던데요, 혹시 첫번째 방법으로 함수를 구현했을 때도 올바로 작동 가능할까요?
const aPipeFn = _.pipe(
_.pick([ 'pick1', 'pick2' ]),
_.partial(_.extend, _, { ex1: 'e1', ex2: 'e2' }),
)
위와 같이 aPipeFn 을 정의하면 되긴 하는데 코드의 가독성 / 일관성 측면에선 첫번째 방법이 제일 좋아보여서요~
webpack 사용중이며 아래와 같은 에러가 발생합니다.
1156라인에서도 동일에러가 발생합니다.
ERROR in ./node_modules/partial-js/partial.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Argument name clash in strict mode (1150:57)
1148 |
1149 | // async not supported
1150 | _.find_i = _.findIndex = collf(function(data, iter, X, X, i, l) {
| ^
1151 | while (++i < l) if (iter(data[i], i, data)) return i;
1152 | return -1;
1153 | });
이렇게 훌륭한 라이브러리가 크게 이슈되지 않는게 이슈라서 글 남깁니다.
개인적으로 함수형 자바스크립트 프로그래밍책은 마이클포거스의 함수형 자바스크립트 책만큼 가치있다고 생각합니다. 아니 솔직히 조금 더 훌륭하다고 생각합니다.
처음에는 너무 난해해서 덮었다가, 두번째에 그 진가를 깨닫게 되고 세번째에 확신을 가지게 되는 점에서
마이클포거스의 책과 같지만
그 분의 책은 비동기 처리를 본질적으로 해결하지 못한점에서 이론적인 반면, 유인동 개발자님께서 쓰신 책은 그 부분을 본질적으로 해결했다는 점에서 굉장히 실무적이라는 점에서 다르다고 봅니다. 그점에서 다르고 그래서 더 훌륭하다고 생각합니다.
지금 세번째 읽고 있습니다. 매일 한쪽한쪽 곱씹어가면서 보고 있는데 왜 이렇게 훌륭한 책과 라이브러리가 크게 이슈화 되지않고 있는지.. 모르겠습니다. 아니겠죠? 어쩌면 제가 체감하지 못하고 있는 걸지도요 :) 그렇게 매일 감탄하다가 이 마음을 어떻게 전해드릴 수 있을까 고심하다 이곳에 남깁니다.
원서가 한국말인 책을 읽으면서 웬지 모르게 자랑스럽기도 하고 그래서 더욱 감사합니다!
npm을 통한 설치 방법 안내에
https://marpple.github.io/partial.js/#Partial-js-%EC%84%A4%EC%B9%98
https://github.com/marpple/partial.js
npm intall --save partial-js
라고 되어있습니다.
npm install --save partial-js
를 의도하신건가요?
const go = __.go(
resp['respCode'],
__.all(
__.negate(_.isUndefined),
__.partial(__.isEqual(code))
),
function() {
return __.toArray(arguments);
},
__.every);
resp['respCode']가 undefined가 아니고 code와 일치할때만 실행이 되는 함수조각인데요. _.all에서 가져온 값을 배열로 바꾸고 싶은데 혹시 저런식으로 함수로 감싸지 않고 partial.js의 내장함수로 대체할 방법이 있을까요? 아님 더 좋은 방법이 있을지도 문의드립니다.
안녕하세요. 책을 스터디 하던 중 다음 코드가 작동 되지 않아 문의 드립니다.
_.find_where함수 부분에서 결과값이 undefined가 떨어집니다. partial적용 하기 전에는 정상적으로 값이 출력되었고요.
최신 버전으로 update해도 나타나는 문제입니다. 확인 부탁드립니다 :)
_.is_match = _.every(function(a, b_val, b_key) { return a[b_key] === b_val; });
// 부분 커링 + predicate 에게 인자 더 넘기기
_.find_where = function(list, attrs) {
return _.find(list, (.is_match, _, attrs));
};
console.log(
_.find_where([{ id: 1, name: "ID" }, { id: 2, name: "CJ" }], { id: 1 })
);
// { id: 1, name: "ID" } => undefined가 떨어집니다.
console.log(
_.is_match({ id: 5, name: "PJ" }, { id: 5 })
);
// true
https://marpple.github.io/partial.js/
여기서 npm 설치하는 부분에 install에서 s가 빠져있습니다.
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.