Giter VIP home page Giter VIP logo

elm-bag's Introduction

elm-bag

Two implementations of a bag using a dict and an association list

{-| type of List.Bag -}
type alias Bag a =
    List (a, Int)

{-| type of Bag -}
type alias Bag comparable a =
    { content : Dict comparable ( a, Int )
    , encode : a -> comparable
    }

Install

elm install Orasund/elm-bag

Usage

You should use the list implementation if

  • Your keys are not comparable
  • You expect to only have a small amount of keys (< 10)
  • The order you insert elements should be preserved (the first item you put into your shopping cart should stay the first item in the list)
  • You need to compare two bags
  • Performance is not an issue

else use the dict implementation

Performance

I did a few performance test and can say that the list implementation always behaved worse then using a dict.

For a smaller amount of keys the different is however not noticeable (at around 50 keys the association list needs roughly double the amount of time to insert or count elements compared to a dict.)

I would assume that for <10 keys you will not notice a difference.

Alternatives

Only alternative so far has been JohnBugner/elm-bag, which I used as a clear inspiration to this package. While JohnBugner used a normal dictionary, i used the same approach as the AnyDict implementation by turboMaCk.

I want to give credit to both JohnBugner and TurboMaCk for their contribution to the elm community. This package is just the combination of the previous works of both of them.

elm-bag's People

Contributors

orasund avatar

Watchers

 avatar

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.