immutable-js | Immutable persistent data collections for Javascript | Dataset library

 by   immutable-js TypeScript Version: v4.3.0 License: MIT

kandi X-RAY | immutable-js Summary

kandi X-RAY | immutable-js Summary

immutable-js is a TypeScript library typically used in Artificial Intelligence, Dataset applications. immutable-js has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Immutable data cannot be changed once created, leading to much simpler application development, no defensive copying, and enabling advanced memoization and change detection techniques with simple logic. Persistent data presents a mutative API which does not update the data in-place, but instead always yields new updated data. Immutable.js provides many Persistent Immutable data structures including: List, Stack, Map, OrderedMap, Set, OrderedSet and Record. These data structures are highly efficient on modern JavaScript VMs by using structural sharing via hash maps tries and vector tries as popularized by Clojure and Scala, minimizing the need to copy or cache data. Immutable.js also provides a lazy Seq, allowing efficient chaining of collection methods like map and filter without creating intermediate representations. Create some Seq with Range and Repeat.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              immutable-js has a medium active ecosystem.
              It has 32608 star(s) with 1860 fork(s). There are 521 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 99 open issues and 1122 have been closed. On average issues are closed in 430 days. There are 22 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of immutable-js is v4.3.0

            kandi-Quality Quality

              immutable-js has 0 bugs and 0 code smells.

            kandi-Security Security

              immutable-js has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              immutable-js code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              immutable-js is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              immutable-js releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              immutable-js saves you 299 person hours of effort in developing the same functionality from scratch.
              It has 501 lines of code, 0 functions and 183 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed immutable-js and discovered the below as its top functions. This is intended to give you an instant insight into immutable-js implemented functionality, and help decide if they suit your requirements.
            • Set bounds of range .
            • Creates a new slice from the current collection .
            • Create a hash for the JS object .
            • Iterate over a list .
            • ZIP iterator generator
            • Flattens a sequence
            • PURE_IMPORTS_START _util_iterator PURE_IMPORTS_END
            • Concatenates a collection and returns a new array with the values that are querying .
            • Updates the ordered map with the given value .
            • Updates the index of the given node in the list .
            Get all kandi verified functions for this library.

            immutable-js Key Features

            No Key Features are available at this moment for immutable-js.

            immutable-js Examples and Code Snippets

            Do multiple regex changes in one update with the help of plpgsql
            JavaScriptdot img1Lines of Code : 22dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            CREATE OR REPLACE FUNCTION clean_column(INOUT _text text)
              LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE AS
            $func$
            DECLARE
               _reg CONSTANT text[] := ARRAY[ 
                   ['search','replace']
                 , ['search','replace']
                 , ['search','repl
            How to filter JSON array elememts by type of value?
            JavaScriptdot img2Lines of Code : 9dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            CREATE OR REPLACE FUNCTION public.fun(j json)
              RETURNS text
              LANGUAGE sql IMMUTABLE PARALLEL SAFE AS
            $func$
            SELECT string_agg(elem ->> 'insert', ' ')
            FROM   json_array_elements(j -> 'ops') elem
            WHERE  json_typeof(elem->'inser
            Alter column type deleting those that can't be converted
            JavaScriptdot img3Lines of Code : 16dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ALTER TABLE table_name ALTER COLUMN col TYPE UUID USING uuid_or_null(col);
            delete from table_name where col is null;
            
            create function uuid_or_null(s text) returns uuid immutable AS
            $$
            begin
              return s::uuid;
            excepti
            Change part of a timestamp (not relatively) in PostgreSQL
            JavaScriptdot img4Lines of Code : 22dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            create or replace function timestamp_set(unit text, tstamp timestamp, num int)
            returns timestamp language sql immutable as $$
                select tstamp+ (num- date_part(unit, tstamp))* format('1 %s', unit)::interval
            $$;
            
            se
            Should I be getting an error when modifying a literal list?
            JavaScriptdot img5Lines of Code : 6dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            > (define (g) '(1 2 3))
            > (g)
            (1 2 3)
            > (set-car! (g) 0)
            ERROR on line 3: set-car!: immutable pair: (1 2 3)
            
            Unique index with a lots of columns
            JavaScriptdot img6Lines of Code : 13dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            CREATE UNIQUE INDEX tbl_row_uni ON tbl (hash_record_extended(tbl.*,0));
            
            CREATE UNIQUE INDEX tbl_row_uni ON tbl (hash_record_extended(tbl,0));
            
            CREATE OR REPLACE FUNCTION public.f_tbl_bighash
            How to create nested object directory name till it found a file
            JavaScriptdot img7Lines of Code : 94dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            { 
              dir: "foo",
              sub_dir: { ... },
              sub_dir: { ... }, // cannot reuse "sub_dir" key
            }
            
            { 
              "test1":
                {
                  "test2":
                     {
                        "test3":
                          {    
                            "0001.dcm": true,
                
            Create function REGEX for optimization
            JavaScriptdot img8Lines of Code : 20dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            CREATE OR REPLACE FUNCTION regex(NAME VARCHAR)
            RETURNS string
            LANGUAGE javascript 
            STRICT IMMUTABLE AS
            $$
                const regex = /[[]\s{0,5}v\s{0,5}=\s{0,5}([0-9]+)/i;
                let s = NAME.match(regex);
                if (s != null) {
                    return s[0].spli
            Remove Diacritics from string in Snowflake
            JavaScriptdot img9Lines of Code : 11dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            create or replace function REPLACE_DIACRITICS("str" string)
            returns string
            language javascript
            strict immutable
            as
            $$
                return str.normalize("NFD").replace(/\p{Diacritic}/gu, "");
            $$;
            
            select REPLACE_DIACRITICS('ö, é, č => a, o e, c')
            Streamlined solution for division on similar subqueries
            JavaScriptdot img10Lines of Code : 18dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            SELECT count(*) FILTER (WHERE source = 'Netflix') * 100.0
                 / count(*) AS visitors_percentage
            FROM   visits.visitors_log
            WHERE  day >= timestamp '2019-12-22' AT TIME ZONE 'PST'
            AND    day <  timestamp '2019-12-23' AT TIME ZONE 'PS

            Community Discussions

            QUESTION

            Immutable.js difference between toJSON() and toObject() on Record
            Asked 2022-Mar-24 at 13:20

            With the release of Immutable v4, there has been some api changes.

            toJS(): any became toJS(): {[key: string]: unknown}

            From what I understand it has been replaced by toJSON() but what's the difference with toObject() ? The documentation isn't very clear on that topic.

            ...

            ANSWER

            Answered 2022-Mar-24 at 13:20

            The names can be taken literally:

            toObject creates javascript plain objects, while toJSON chooses the datatype based on the collection type.

            For keyed collections (Record, Map, OrderedMap), toJSON and toObject do the same.

            However, for list types (Lists, Set, OrderedSet) there is a difference: toJSON returns an Array, while toObject generates an Object where the keys are the indexes:

            Source https://stackoverflow.com/questions/71585780

            QUESTION

            Type 'string' is not assignable to type keyof in Immutable.js
            Asked 2021-Nov-03 at 12:26

            I got this typing error when trying to use immutable js reviver from fromJS function.

            Check this TS playground, I could reproduce it there.

            ...

            ANSWER

            Answered 2021-Nov-02 at 23:10

            Not sure if this breaks any of your functionality as I have little context of exactly what you are trying to do. But you can get rid of the error by saying that you want key of user in fromJS, like this:

            Source https://stackoverflow.com/questions/69817681

            QUESTION

            "First Load JS" size problem Next.js. (Using immutable.js)
            Asked 2021-Aug-20 at 09:09

            In my project(Next.js v10), the immutable library is used to work with redux. Now I tackled the issue of optimization, because I ran into the problem of "red" first load js.

            I am not very strong in this yet, but I try to learn and understand everything. I applied dynamic import on the pages themselves, as it is advised everywhere, and it helped a lot, since the situation was even worse than now. I checked _document.js and _app.js, everything seems to be fine except:

            ...

            ANSWER

            Answered 2021-Aug-20 at 09:09

            I published the results of my work, I hope this will help someone(Sorry for my English :)).

            Ditching immutable.js in favor of Immer did make sense (156 => 123):

            Also, if anyone is interested, take a closer look at your chunks. As you can see from my question, in addition to Immutable, http-status.js was also "added" to the general First Load JS. This is a standard file with a set of response codes, from which I needed only one (I just wrote the number manually and removed the import), and the file where it was imported is distributed to the entire application. Additionally, I revised the connection of third-party scripts and used the internal optimization of fonts in next v10:

            Also, in conjunction with immutable, json-immutable was used, which is no longer required, which removed 2 more small chunks.

            And my previously problematic chunk now looks like this:

            Finally: "First Load JS shared by all" has been reduced from 156 kB to 111kB (28.85%)

            P.S. I have such a big _app.js chunk because I have Automatic Static Optimization disabled due to getInitialProps

            Source https://stackoverflow.com/questions/68800917

            QUESTION

            How to remove a nested array element in Redux Reducer?
            Asked 2021-Apr-28 at 09:29

            been banging my head against this for hours.

            I am trying to remove a nested elment of an array in an object. It must be done immutably within a reducer, which is making it tricky.

            Here is the object:

            ...

            ANSWER

            Answered 2021-Apr-28 at 06:26

            First of clone your questions object by using ... ES6 operator

            const clonedQuestion = {...questions}

            Now for removing element from answers array

            Source https://stackoverflow.com/questions/67294496

            QUESTION

            What persistent data structures does Raku/Rakudo include?
            Asked 2021-Apr-10 at 15:02

            Raku provides many types that are immutable and thus cannot be modified after they are created. Until I started looking into this area recently, my understanding was that these Types were not persistent data structures – that is, unlike the core types in Clojure or Haskell, my belief was that Raku's immutable types did not take advantage of structural sharing to allow for inexpensive copies. I thought that statement my List $new = (|$old-list, 42); literally copied the values in $old-list, without the data-sharing features of persistent data structures.

            That description of my understanding is in the past tense, however, due to the following code:

            ...

            ANSWER

            Answered 2021-Apr-10 at 15:02

            I remember implementing these semantics, and I certainly don't recall thinking about them giving rise to a persistent data structure at the time - although it does seems fair to attach that label to the result!

            I don't think you'll find anywhere that explicitly spells out this exact behavior, however the most natural implementation of things that are required by the language quite naturally leads to it. Taking the ingredients:

            • The infix:<,> operator is the List constructor in Raku
            • When a List is created, it is non-committal with regards to laziness and flattening (these arise from how we use the List, which we don't - in general - know at the point of its construction)
            • When we write (|$x, 1), the prefix:<|> operator constructs a Slip, which is a kind of List that should melt into its surrounding List. Thus what infix:<,> sees is a Slip and an Int.
            • Making the Slip melt into the result List immediately would mean making a commitment about eagerness, which List construction alone should not do. Thus the Slip and everything after it is placed into the lazily evaluated ("non-reified") portion of the List.

            This last of these is what gives rise to the observed persistent data structure style behavior.

            I expect it would be possible to have a implementation that inspects the Slip and chooses to eagerly copy things that are known not to be lazy, and still be in compliance with the specification test suite. That would change the time complexity of your example. If you want to be defensive against that, then:

            Source https://stackoverflow.com/questions/67030459

            QUESTION

            Typescript: correctly infer arguments and return type for wrapped function
            Asked 2020-Oct-18 at 00:30

            I'm trying to create a wrapper function that takes in a query and a reducer, then returns essentially the same function, but with an additional property (_data) that contains a processed version of the query data (specifically, I want to cast the query result to an Immutable.js record).

            I'd like this function to be generic over any possible query, and preserve the call signature and type information from the query. I've attempted to do this by using Parameters and ReturnType. However, when I pass the arguments to queryHook in the inner function, Typescript complains that the arguments aren't assignable to the inner function, even though they should be typed from that function's parameters.

            My question is, why can't Typescript tell that the arguments being passed to the wrapped query should be of identical type to the the query's expected arguments?

            Currently, it gives an error that suggests that the queryHook could be any of the possible queries, not the specific one that was passed to the function.

            Weirdly, if I actually use the function, all types are inferred correctly...

            My code is as follows:

            ...

            ANSWER

            Answered 2020-Oct-18 at 00:30

            Instead of trying to work backwards based on the signatures of two particular hooks, let's try to make a more generalized function. Typescript should be able to infer the specific types based on which hook you pass in as an argument.

            Start by thinking about what we know and what we don't know. The things that we don't know become the generics.

            • A hook is a function which takes some arguments (A). There can be any number of arguments of any type (A extends any[]).
            • It returns some object (R) which might have a property called 'data' (R extends { data?: any }).
            • A reducer is a function which takes the data returned by the hook (R['data']) and maps it to some new value (M).
            • The modified hook takes the same arguments (A) and returns an object with all of the hook returned values (R) and an additional property '_data' whose value is returned from the reducer (M) or might be undefined (R & { _data: M | undefined }).

            Put that all together and we get this:

            Source https://stackoverflow.com/questions/64405339

            QUESTION

            Time complexity between two iterate methods of immutable collection
            Asked 2020-Oct-15 at 09:37

            There is an Immutable.js with the structural data as collections. Let's take a Map. Also there are methods to work with:

            • includes
            • filter

            Let's consider these data:

            ...

            ANSWER

            Answered 2020-Oct-15 at 09:37

            As you pointed out, the semantics are slightly different. In the example case they both provide an intersection of the ids, so

            Source https://stackoverflow.com/questions/64332167

            QUESTION

            studying immutable and can't understand what they say
            Asked 2020-Jul-01 at 11:58

            I'm studying about record of immutable.js.

            but this code almost kill me.

            My Question

            1. I know [import, export,const] but [type] is what mean.

            2. defaultValues:, makePoint3D:, getName(): string, setName(name: string): this what mean. I never seen : unless in object or if .

            This question is key for my understanding.

            please give me advice!

            ...

            ANSWER

            Answered 2020-Jul-01 at 09:11

            getName(): string , getName() is your method and part after : tells about return type. Basically part after : usually denotes about type . return type , variable type etc whatever you are using

            Source https://stackoverflow.com/questions/62668964

            QUESTION

            Immutable as React state
            Asked 2020-Jun-11 at 20:41

            Is this a good solution? https://github.com/immutable-js/immutable-js/wiki/Immutable-as-React-state

            I need to put nested objects in my state. This solution seems simple enough in code, but I'm wondering if there are any reasons not to take this approach.

            ...

            ANSWER

            Answered 2020-Jun-11 at 20:41

            TL/DR: I recommend immutable for anything bigger than a simple news-list, together with redux-saga. But I would and don't use it for component's local state.

            We have a big React app (JS, not TypeScript) that has all the state as Immutable objects. The recommendation usually is the same as with redux and redux-saga: If you don't know why you need it, you probably don't. But here is the thing, if you start without it and later notice that it would be helpful, you are already deep in a mess and it's hard to switch over.

            Immutable doesn't add obvious business value, but it reduces the chances of bugs and prevents you from doing things that might look good now but in the long run increase the cost of development. Especially when your dev team isn't an experienced bunch of seniors or generally tends to not strictly follow rules.

            However, in my opinion, it is unecessary overkill for an components internal state, at least if business state is stored in your global redux state.

            PS: Immutable is mature and probably doesn't need patches much, but it has to be said: Development of immutable essentially is stopped, they are discussing to bring in new people but who knows how that turns out. There are similar libraries which are more active

            Source https://stackoverflow.com/questions/62224037

            QUESTION

            immutable JS with Typescript: "No overload matches this call" when creating Map / OrderedMap
            Asked 2020-Apr-22 at 09:05

            I am using Typescript version 3.8.3 with immutable@4.0.0-rc.12.

            When I create OrderedMap using two-dimensional array to instantiate it, I get error from Typescript.

            ...

            ANSWER

            Answered 2020-Apr-22 at 09:05

            First of all, @types/immutable is no longer supported

            This package has been deprecated

            Author message:

            This is a stub types definition for Facebook's Immutable (https://github.com/facebook/immutable-js). Facebook's Immutable provides its own type definitions, so you don't need @types/immutable installed!

            After removing it, you should get nice type hints in your editor.

            Working example: https://stackblitz.com/edit/typescript-vwetmv?file=index.ts

            Update

            Adding "target": "es2015" in compiler options removes the error.

            See docs: Using TypeScript with Immutable.js v4

            Immutable.js type definitions embrace ES2015. While Immutable.js itself supports legacy browsers and environments, its type definitions require TypeScript's 2015 lib. Include either "target": "es2015" or "lib": "es2015" in your tsconfig.json, or provide --target es2015 or --lib es2015 to the tsc command.

            Source https://stackoverflow.com/questions/61353241

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install immutable-js

            Install immutable using npm. Or install using yarn. Then require it into any module.

            Support

            Use Github issues for requests. We actively welcome pull requests, learn how to contribute. Immutable.js is maintained within the Contributor Covenant's Code of Conduct.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/immutable-js/immutable-js.git

          • CLI

            gh repo clone immutable-js/immutable-js

          • sshUrl

            git@github.com:immutable-js/immutable-js.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link