Repository navigation
v0.26.0
Changed
- Breaking: the public API is now the single
dataprepmodule. Errors accumulate inResult(a, NonEmptyList(e))from thenon_empty_listpackage, a new dependency, andValidator(a, e)isfn(a) -> Result(a, NonEmptyList(e)). Packages that importdataprep/validatedordataprep/non_empty_list, such as datastream's example, need updating. - Breaking: functions that moved into
dataprepwith a new shape or new labels:map2tomap5take the results first and the function last, labelledwith.and_then(first:, then:)replacesvalidator.and_then(pre:, main:), andmap_error(validator, with:)andpredicate(condition, otherwise:)gained labels.collapse_spaceandcollapse_unicode_spacetake aStringand return aStringinstead of returning aPrep.validated.sequenceis nowcollect, andparse.float_strictis nowparse_float, which returnsResult(Float, Nil).rules.matches_fully_string_checkedis nowfull_match, which returnsgleam/regexp'sCompileError. When the pattern compiles on its own but not inside the anchoring wrapper, the error'sbyte_indexis 0 and its message refers to the wrapped pattern.
// Before
import dataprep/prep
import dataprep/rules
import dataprep/validated
validated.map2(
User,
rules.not_empty("name is required")(prep.trim()(name)),
rules.min_int(minimum: 18, error: "must be an adult")(age),
)
// After
import dataprep
import gleam/string
dataprep.map2(
dataprep.not_empty("name is required")(string.trim(name)),
dataprep.min_int(minimum: 18, error: "must be an adult")(age),
with: User,
)Removed
- Breaking: the modules
dataprep/prep,dataprep/validator,dataprep/validated,dataprep/non_empty_list,dataprep/rulesanddataprep/parse, and the type aliases indataprep. Their remaining functions are indataprep. - Breaking: functions that wrap the standard library or another dataprep function: the
Prephelpers (then,compose,sequence,identity,run,trim,lowercase,uppercase,default,default_when_blank,replace,replace_checked),Validatedand itsmap,map_error,and_then,fail,from_result,from_result_map,to_result,combine2tocombine5,and_map,traverse,traverse_indexed,also,required,label,non_negative_int,non_negative_float,equals,length_between,parse.int, the lenientparse.float,matches_string,matches_string_checked,matches_fully_stringandRegexRuleError. Usestring.trim,int.parse,result.map,list.mapwithcollect, andmap_errorinstead. - The guides under
doc/(architecture, laws and recipes), which described the old modules.
Fixed
parse.floatandparse.float_strict(nowparse_float) reject values beyond the largest finite float on both targets. Inputs such as"2.0e308"crashed the process on Erlang and returnedValid(Infinity)on JavaScript. Finite inputs with large exponents, such as"0e999"and"0.1e309", are now accepted on both targets.collect(formerlyvalidated.sequence) andeachno longer overflow the JavaScript stack on long lists. The validator is now applied from the first element to the last.allruns in linear time.collapse_spaceandcollapse_unicode_spacefold the same characters on both targets: the six ASCII whitespace characters, and the Unicode White_Space set. U+FEFF is not treated as whitespace.full_match(formerlyrules.matches_fully_string_checked) rejects patterns that do not compile on their own, such as"a)|(b", and no longer accepts a trailing newline after a match.
Install
gleam add dataprepSee HexDocs for the API
reference.