8000 Releases · erikjuhani/fp-utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Releases: erikjuhani/fp-utils

0.16.0

12 Aug 20:31
Compare
Choose a tag to compare

Full Changelog: 0.15.0...0.16.0

Breaking changes

Change type guards to return never instead of false

Previously when invoking the isOk on Err type or isErr on Ok type
would return always false and the corresponding type would be set as the
original type. This however does not work with the newest TypeScript
version 5.5.3. The failure in this case is correct as the inference
does not work as expected if a false is returned instead of a type
guard.

The 'correct' change here is to instead return never type guard as we
can never enter that block that checks for isErr or isOk on a type that
does not reflect it.

Example:

const ok = Ok(42);

// Previously this was accepted and the type was inferred as Ok in the
// code block
if (ok.isErr()) {
  ok;
  // ^? Ok<number>;
}

// However now the type would be never, which is less flexible, but
// correct behaviour
if (ok.isErr()) {
  ok;
  // ^? never
}

Change type guards to return never instead of false in option

Previously when invoking the isSome on None type or isNone on Some
type would return always false and the corresponding type would be set
as the original type. This however does not work with the newest
TypeScript version 5.5.3. The failure in this case is correct as the
inference does not work as expected if a false is returned instead of a
type guard.

The 'correct' change here is to instead return never type guard as we
can never enter that block that checks for isNone or isSome on a type
that does not reflect it.

Example:

const some = Some(42);

// Previously this was accepted and the type was inferred as Some in the
// code block
if (some.isNone()) {
  some;
  // ^? Some<number>;
}

// However now the type would be never, which is less flexible, but
// correct behaviour
if (some.isNone()) {
  some;
  // ^? never
}

Changes

Add terser to minify code published to npm

Terser is a JavaScript mangler/compressor. More info here:
https://github.com/terser/terser

By utilizing terser the size of the output distribution files is
considerable smaller as the code is compressed and mangled to minimum
functional state. Terser also removes comments, which in turn replaces
the naive comment remove solution that was relying on regex.

The compressed output file size is around 50% smaller from 4.33kb to
2.2kb for option module.

Fixes

Fix details tags in Option and Result README

Some of the details tags were missing ending tag counterpart.

0.15.0

08 Jun 08:22
Compare
Choose a tag to compare

Full Changelog: 0.14.0...0.15.0

Breaking changes

Add Option.toJSON method and static variant

Option.toJSON serializes the option into JSON format. If the option is
None, it will be serialized to null. If the option is Some, it will be
serialized to the unwrapped value T.

This function acts as the interoperability layer between Option type and
TypeScript. For example nullish coalescing can be utilized with this
function.

// Nullish coalescing
const option: Option<string> = None;
const result = option.toJSON() ?? "defaultValue";

// Optional chaining
const option: Option<{ name: string }> = None;
const result = option.toJSON()?.name;

Add Result.toJSON method and static variant

Result.toJSON serializes the result into JSON format. An Ok value will
be serialized to { "ok": T }, and an Err value will be serialized to
{ "err": TError }.

This function acts as the interoperability layer between Result type and
TypeScript.

0.14.0

31 May 20:39
Compare
Choose a tag to compare

Full Changelog: 0.13.1...0.14.0

Breaking changes

The target change affects both Result and Option modules.

Change build_npm target to ES2022 to support cause property

Error cause property is supported from "ES2022" onwards.

Changes

Add cause property when throwing with expect on Err type

This will help to identify the originating error with stacktrace and
orginal error message, otherwise the original error would be lost.

Features

Add Option.all and Option.any static methods

Option.all returns all Some option values as an array within a Some
option. If None option exists in the array, None is returned. An empty
array signifies success, resulting in a Some with an empty array.

Option.any returns the first Some option encountered. If no Some options
are found in the array None is returned.

Add Result.all and Result.any static methods

Result.all returns all Ok result values as an array within an Ok result
if no Err results are present. If any Err result exists in the array,
the first one is returned. An empty array signifies success, resulting
in an Ok with an empty array.

Result.any returns the first Ok result encountered. If no Ok results are
found in the array, all Err result values are returned as an array
within an Err result.

0.13.1

14 May 18:53
Compare
Choose a tag to compare

Full Changelog: 0.13.0...0.13.1

Features

Add Option.toString method and higher-order function variant

Signature: (): "Some(value)" | "None"

Option.toString returns the string representation of the option and the
stringified value as Some(value) if the result is Some or None if
the result is None.

Some(42)
  .toString(); // Evaluates to "Some(42)"

None
  .toString(); // Evaluates to "None"

Custom inspect symbol was "Deno.customInspect" introduced to the
Option classes Some and None to produce more formatted and readable
output for option values using the Option.toString method. For example,
calling console.log(Some(42)); will now print Some(42), whereas
previously, it would have been printed as Some {}.

Add Result.toString method and higher-order function variant

Signature: (): "Ok(value)" | "Err(value)"

Result.toString returns the string representation of the result and the
stringified value as Ok(value) if the result is Ok or Err(value)
if the result is Err.

Ok(42)
  .toString(); // Evaluates to "Ok(42)"

Err(42)
  .toString(); // Evaluates to "Err(42)"

Custom inspect symbol was "Deno.customInspect" introduced to the
Result classes Ok and Err to produce more formatted and readable
output for result values using the Result.toString method. For example,
calling console.log(Ok(42)); will now print Ok(42), whereas
previously, it would have been printed as Ok {}.

Add Result.partition static method

Result.partition unwraps an array of results into a tuple of unwrapped
Ok and Err values. This is especially useful if for example all errors
and success cases need to be evaluated individually.

0.13.0

19 Apr 19:18
Compare
Choose a tag to compare