Skip to content

Releases: rolandpeelen/melange-pancake

Melange

09 Nov 14:46
Compare
Choose a tag to compare
2.0.1

2.0.1

Update to OCaml

05 Nov 17:42
Compare
Choose a tag to compare
v1.4.0

Version 1.4.0

Add Lens.effect

01 Jul 07:11
bab1033
Compare
Choose a tag to compare

One often has the need to do side-effecty stuff, doing something like
map >> ignore. The effect function is here to make that pattern
easier to deal with

Add Windows Support

30 Jun 22:31
Compare
Choose a tag to compare
v1.2.7

Add Windows Support

Update PPXLib version

04 Jun 20:39
Compare
Choose a tag to compare

This release updates the PPXLib version so it can be compiled with latest ocaml

Add License (BSD 3-clause)

19 Oct 09:02
Compare
Choose a tag to compare
v1.2.2

Release version v1.2.2

Fix Stackoverflow

04 Aug 20:20
a6cf623
Compare
Choose a tag to compare

As it turns out this got compiled to a while loop in Bucklescript,

  let rec findBy = fn =>
    fun
    | [] => None
    | [x, ..._] when fn(x) => Some(x)
    | [_, ...xs] => findBy(fn, xs);

But this didn't.

  let rec replaceBy = (e, fn) =>
    fun
    | [] => []
    | [x, ...xs] when fn(x) => [e, ...xs]
    | [x, ...xs] => [x, ...replaceBy(e, fn, xs)];

In the Array version we simply map as slicing the array is O(n) anyway. For the linked list, I figured we could be more clever and simple join the rest of the list back onto itself when we've found the element. There were some attempts at cleverness, using an accumulator, but those ended up just being slower, as the accumulator would have to append to keep the list ordered, which is slow. Prepending and then reversing the list is another O(n) operation, meaning in the worst case scenario we would run 0(n*2).

This is now just a map.

FindBy / FindByLens for Array / List

04 Aug 19:09
93337da
Compare
Choose a tag to compare

This release adds a lens for finding elements in an Array or List.

Either directly, if you can provide the full item to find

Lens.set(
  Lens.List.find(5) >>- Lens.Option.orExn,
  200,
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
)
|> expect
|> toEqual([0, 1, 2, 3, 4, 200, 6, 7, 8, 9, 10])

Or by providing an additional lens to find something by a record.

[@pancake]
type user = {
  id: int,
  username: string,
};
let users = [
  {id: 0, username: "0"},
  {id: 1, username: "1"},
  {id: 2, username: "2"},
  {id: 3, username: "3"},
];

Lens.view(Lens.List.findByLens(0, userIdLens), users)
|> expect
|> toEqual(Some({id: 0, username: "0"}))

Checkout the tests for lists, arrays, or this arbitrarily complicated nested thing to see some more examples (and how they compose into Lens.Option to add fallback values, or throw exceptions when they're not found

v1.1.0 -- List / Array / Option / Result / Tests

03 Aug 21:26
Compare
Choose a tag to compare

We now support some extra helpers;

List & Array

  • Lens.List.atOrElse
  • Lens.Array.atOrElse

Takes an integer, and a default. When viewing, it will try to view the element. If it's out of bounds, it will return the default. When setting, it will set the element if it's in bounds, and return the original array if it's out of bounds. You can supply negative integers to wrap around (ie. -1 is the last element)

  • Lens.List.atOrExn
  • Lens.Array.atOrExn
    Same as atOrElse, but will throw when out of bounds

Option & Result

  • Lens.Option.orElse

  • Lens.Result.orElse
    These will take a default value, when it is either None or Error(...), they will return the default when viewing. Setting will always be wrapped in either Some(...) or Ok(...).

  • Lens.Option.orExn

  • Lens.Result.orExn
    Same as orElse, but will throw when out of bounds

We've also made sure these are covered by tests properly...

v1.0.5

18 Jul 15:19
Compare
Choose a tag to compare

This release uses the pre-build variant, as build by CI