Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Array module #27

Merged
merged 3 commits into from Apr 6, 2019
Merged

Add the Array module #27

merged 3 commits into from Apr 6, 2019

Conversation

Dean177
Copy link
Collaborator

@Dean177 Dean177 commented Apr 1, 2019

I started from @j-m-hoffmann 's pull request #14 and in an effort to have a more manageable PR I

  • removed a lot of the functions, so it is still quite incomplete compared to List or Base / Belt
  • Added tests and documentation for each of the functions

I also added a teeny Int module since it made writing the examples / tests easier.

This differs from Elms Array module in the following ways:

  • The addition of the singleton, range, map2, flatMap, set any, all, append, concatenate, flatten, intersperse, reverse, reverseInPlace & forEach functions.
  • The omission of push
  • indexedMap -> mapWithIndex
  • foldl -> foldLeft & foldr -> foldRight, additionally both functions have slightly different signatures
  • slice uses a named and optional parameter

@pbiggar
Copy link
Member

pbiggar commented Apr 1, 2019

This is great thanks!

What's happening with the odoc stuff? That's suddenly very unreadable.

We're also at a place where there's like 4 of us using different ocamlformat settings, and this PR is suffering from it in particular. Could you take a glance at #7?

@Dean177
Copy link
Collaborator Author

Dean177 commented Apr 1, 2019

Sure, I will look at getting ocamlformat set up.

What do you mean by odoc stuff?

bs/src/tablecloth.mli Outdated Show resolved Hide resolved
@pbiggar
Copy link
Member

pbiggar commented Apr 3, 2019

What do you mean by odoc stuff?

This stuff here: https://github.com/darklang/tablecloth/pull/27/files#diff-484204121b3d8dfb8718cebe802a55a9R2

@Dean177
Copy link
Collaborator Author

Dean177 commented Apr 3, 2019

I have rebased out the changes to bs/tablecloth.mli.

@pbiggar
Copy link
Member

pbiggar commented Apr 4, 2019

Great, thanks.

So a thing that I just noticed is that this array is mutable. The Elm one is not of course. The Belt one is mutable, as are the Batteries one and the OCaml one.

I'd love to hear some thoughts on this.

@j-m-hoffmann
Copy link

hey Dean, good job so far. As you can see in the benchmark in PR #26, using flip to force functions from Ocaml that use accumulator first to conform to the Elm Style of element first is a bad idea™

bs/src/tablecloth.ml Outdated Show resolved Hide resolved
bs/src/tablecloth.ml Outdated Show resolved Hide resolved
bs/src/tablecloth.ml Outdated Show resolved Hide resolved
Base.Array.fold ~f:(fun b a -> f a b) ~init:initial a

let fold_left = foldLeft

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a foldl alias?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let foldl = foldLeft

Base.Array.fold_right ~f ~init:initial a

let fold_right = foldRight

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias to foldr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a slightly different signature (initial rather than init).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let foldr = foldRight

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you mean add the foldr alias in addition to foldRight and fold_right.

This was an intentional deviation from Elms standard library as I felt it was more in keeping with Elms guidelines on API's: https://package.elm-lang.org/help/design-guidelines#use-human-readable-names

In this particular case the Elm docs even go on to explain that foldr means "fold from the right".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im in a rush, gonna read it when i have time. My thought was we have indexedMap/mapi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove mapi and all synonyms - have just one way to do it.

@Dean177
Copy link
Collaborator Author

Dean177 commented Apr 4, 2019

I think we should stick with Array being mutable and potentially offer an immutable alternative with a name other than Array.

I figure we need to inter-operate on two fronts: Javascript and native OCaml, both of those have mutable Arrays and having a collection with the same name name but different behaviour would be potentially confusing.

@pbiggar
Copy link
Member

pbiggar commented Apr 4, 2019

OK, happy to go with the mutable version, thanks for the opinion. If you want to go through @j-m-hoffmann's review/suggestions and either fix them or decide not to, then we can get this merged.

…place of `Array.of_list` for `bs`.Remove the now unused `Caml` module.Use Base.Array.init in place of Array.init for native
@Dean177
Copy link
Collaborator Author

Dean177 commented Apr 6, 2019

@j-m-hoffmann are you happy your comments have been addressed?

If so I think that means this is ready @pbiggar

@pbiggar
Copy link
Member

pbiggar commented Apr 6, 2019

Gonna merge this now, to avoid future conflicts. @j-m-hoffmann, if you wanna comment on this PR we can get the addressed after.

@pbiggar pbiggar merged commit adf9a33 into darklang:master Apr 6, 2019
@Dean177 Dean177 deleted the add-array-module branch April 7, 2019 08:57
Lomand pushed a commit to Lomand/tablecloth that referenced this pull request Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants