gong023 / underscore-rust

utility library for rust

Home Page:http://gong023.github.io/underscore-rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the style.

benjycui opened this issue · comments

Not the code style, but the style of APIs. I am a JavaScript programmer and rust novice, and I am very interest in this project. But when read your readme.md, I found that the APIs' style is very different from underscore.js. So, is it impossible to imitate that style in Rust, or you have consider more? THANKS.

Hi, benjycui. Thank you for your pointing out. I try to rewrite README to clear difference between underscore.js, underscore-rust and rust std library. Wait a moment please.

First, it is possible to imitate original style. In fact, I had been implemented in original style.

But I thought vec!(1i, 2, 3).first() betters than __.first(vec!(1i, 2, 3) because

  • it is in accordance with the OOP
  • you need not consider about type at first argument
    • __.first imply incorrect type at first argument like __.first(HashMap::new())

If you're embarrassed to be compared with the original function, refer to the following my notes (I'm going to include soon the following note in the README)

underscore.js underscore-rust rust std library
Collections#each not implemented yet -
Collections#map - std::iter::Map::map
Collections#reduce - std::iter::Scan::scan
Collections#reduceRight not implemented yet -
Collections#find - std::iter::Filter::find
Collections#filter - std::iter::Filter::filter
Collections#where - -
Collections#findWhere not necessary in rust -
Collections#reject reject
Collections#every - std::iter::Iterator::all
Collections#some - std::iter::Iterator::any
Collections#contains - collections::vec::Vec::contains etc
Collections#invoke difficult to implement in rust -
Collections#pluck - -
Collections#max - core::slice::Items::max_by
Collections#min - core::slice::Items::min_by
Collections#sortBy - collections::vec::Vec::sort_by
Collections#groupBy - -
Collections#indexBy - -
Collections#countBy - -
Collections#shuffle - std::rand::Rng::shuffle
Collections#sample - std::rand::sample
Collections#toArray - -
Collections#size - std::collections::Collection::len
Collections#partition difficult to implement in rust -
Arrays#first first -
Arrays#initial - collections::vec::Vec::init
Arrays#last - collections::vec::Vec::last
Arrays#rest - collections::vec::Vec::tailn
Arrays#compact not necessary in rust -
Arrays#flatten not implemented yet -
Arrays#without without -
Arrays#union - collections::vec::Vec::add
Arrays#intersection intersection -
Arrays#difference not implemented yet -
Arrays#uniq uniq -
Arrays#zip not implemented yet -
Arrays#object - -
Arrays#indexOf indexOf -
Arrays#lastIndexOf lastIndexOf -
Arrays#sortedIndex - -
Arrays#range - std::iter::range
Functions#bind - -
Functions#bindAll - -
Functions#partial - -
Functions#memoize - -
Functions#delay - -
Functions#defer - -
Functions#throttle - -
Functions#debounce - -
Functions#once - -
Functions#after - -
Functions#before - -
Functions#wrap - -
Functions#negate - -
Functions#compose - -
Objects#keys - std::collections::HashMap::keys
Objects#values - std::collections::HashMap::values
Objects#pairs pairs -
Objects#invert invert -
Objects#functions difficult to implement in rust -
Objects#extend difficult to implement in rust -
Objects#pick pick -
Objects#omit omit -
Objects#defaults defaults -
Objects#clone - std::clone::Clone
Objects#tap difficult to implement in rust -
Objects#has - std::collections::HashMap::contains_key
Objects#matches - -
Objects#property - -
Objects#isEqual not necessary in rust -
Objects#isEmpty - -
Objects#isElement not necessary in rust -
Objects#isArray not necessary in rust -
Objects#isObject not necessary in rust -
Objects#isArguments not necessary in rust -
Objects#isFunction not necessary in rust -
Objects#isString not necessary in rust -
Objects#isNumber not necessary in rust -
Objects#isFinite not necessary in rust -
Objects#isBoolean not necessary in rust -
Objects#isDate not necessary in rust -
Objects#isRegExp not necessary in rust -
Objects#isNaN not necessary in rust -
Objects#isNull not necessary in rust -
Objects#isUndefined not necessary in rust -
Utility#noConflict not necessary -
Utility#identity - -
Utility#constant - -
Utility#noop - -
Utility#times - -
Utility#random - -
Utility#mixin - -
Utility#iteratee - -
Utility#uniqueId - -
Utility#escape - -
Utility#unescape - -
Utility#result - -
Utility#now - time::now
Utility#template - -
Chaining#chain - -
Chaining#value - -

Brilliant! So, underscore-rust is a complement of Rust std library, inspired by underscore.js but not a port of it, right? THANKS.

Yes.

I'm still thinking about design. If you have other opinion, feel free to send issue or code.

Thank you for answering my questions :)