Giter VIP home page Giter VIP logo

jfmengels / non-empty-list-alias Goto Github PK

View Code? Open in Web Editor NEW

This project forked from turbomack/non-empty-list-alias

0.0 1.0 0.0 52 KB

Functions for NonEmptyList you already have and Zipper implementation that goes with it.

Home Page: https://package.elm-lang.org/packages/turboMaCk/non-empty-list-alias/latest/

License: BSD 3-Clause "New" or "Revised" License

Elm 99.76% Makefile 0.24%

non-empty-list-alias's Introduction

List.NonEmpty alias with Zipper

Build Status

Functions for NonEmpty list you already have and Zipper implementation that goes with it.

Implementation of non-empty list defined as alias to pair (a, List a). This means that producing or consuming type compatible with this library doesn't require having it as a dependecy. Despite this, this package aims to provide the most feature complete implementation of non-empty list for Elm and includes variety of practical functions from JSON decoder helpers to hi-level combinators like duplicate and extend.

Motivation

elm/core doesn't come with non empty list type. This means one usually has to rely library implementations of NonEmpty type:

These implementations usually define custom data type like NonEmpty a = Cons a (List a) and expose the constructor to make pattern matching possible. This makes it hard for library authors to provide support for NonEmpty, because they would need to pick one of these libraries and use it as a dependency of their own implementation and essentially impose this decision onto their users.

This implementation uses different approach. NonEmpty is an alias for the pair type alias NonEmpty a = (a, List a). Relying on anonymous data-type like tuple means:

  1. Libraries can produce NonEmpty data without depending on specific (including this) implementation.
  2. Implementation provided by this package can be easily replaced by different implementation using the same type definition.
  3. Users may choose to work with tuple directly without need to transform from and to NonEmpty type.

Zipper

One of the downsides of common approache is also noticable with available list zipper implementations.

All of above are usually constructed using List a -> Maybe (Zipper a) without posibility to construct zipper as NonEmpty a -> Zipper a. The motivation behind including Zipper in this package is to encourage its usage together with NonEmpty list. My favorite implementation of list zipper which doesn't rely on NonEmpty is zwilias/elm-holey-zipper.

Drawbacks

Compared to other implementations this implementation has less descriptive constructor in value space. This means that pattern matching happens on the pair instead of explicit constructor like Cons or NonEmpty.

conventional library:

matchNonEmpty : NonEmptyList a -> foo
matchNonEmpty (Cons h t) =
    .....

With this library:

matchNonEmpty : NonEmptyList a -> foo
matchNonEmpty (h, t) =
    .....

For Haskell Fanbois

List.NoneEmpty.NonEmpty is:

  • Functor
  • Foldable
  • Applicative
  • Monad
  • Comonad

List.NonEmpty.Zipper is:

  • Functor
  • Foldable
  • Applicative
  • Comonad

non-empty-list-alias's People

Contributors

turbomack avatar kubaracek avatar kutyel avatar jhrcek avatar kurren123 avatar kraklin 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.