- Jun 2023
-
bugzilla.mozilla.org bugzilla.mozilla.org
Tags
Annotators
URL
-
-
github.com github.com
- May 2023
-
github.com github.com
-
jsdoc /* * @pattern /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/ */
Tags
Annotators
URL
-
- Mar 2023
-
www.erlang.org www.erlang.org
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
-
z-pattern-matching.github.io z-pattern-matching.github.io
-
- Matches by Object property ```js const { matches } = require('z')
const person = { name: 'Maria' } matches(person)( (x = { name: 'John' }) => console.log('John you are not welcome!'), (x) => console.log(
Hey ${x.name}, you are welcome!
) )- Matches by type or instances
js const { matches } = require('z')const result = matches(1)( (x = 2) => 'number 2 is the best!!!', (x = Number) =>
number ${x} is not that good
, (x = Date) => 'blaa.. dates are awful!' )console.log(result) // output: number 1 is not that good
- Matches Array content
js const { matches } = require('z')matches([1, 2, 3, 4, 5])( (a, b, c, tail) => 'a = 1, b = 2, c = 3, tail = [4, 5]'<br /> )
matches([1, 2])( (a, tail) => 'a = 1, tail = [2]'<br /> )
matches([1])( (a, b, tail) => 'Will not match here', (a = 2, tail = []) => 'Will not match here', (a = 1, tail) => 'Will match here, tail = []' ) ```
- Powerful recursive code which will remove sequential repeated items from Array ```js const { matches } = require('z')
const compress = (numbers) => { return matches(numbers)( (x, y, xs) => x === y ? compress([x].concat(xs)) : [x].concat(compress([y].concat(xs))), (x, xs) => x // stopping condition ) }
compress([1, 1, 2, 3, 4, 4, 4]) //output: [1, 2, 3, 4] ```
Tags
Annotators
URL
-
-
www.proposals.es www.proposals.es
-
js match (res) { if (isEmpty(res)) { … } when ({ pages, data }) if (pages > 1) { … } when ({ pages, data }) if (pages === 1) { … } else { … } }
js match (arithmeticStr) { when (/(?<left>\d+) \+ (?<right>\d+)/) as ({ groups: { left, right } }) { process(left, right); } when (/(?<left>\d+) \+ (?<right>\d+)/) { process(left, right); } // maybe? else { ... } }
```js class Name { static Symbol.matcher { const pieces = matchable.split(' '); if (pieces.length === 2) { return { matched: true, value: pieces }; } } }
match ('Tab Atkins-Bittner') { when (^Name with [first, last]) if (last.includes('-')) { … } when (^Name with [first, last]) { … } else { ... } } ```
js const res = await fetch(jsonService) match (res) { when ({ status: 200, headers: { 'Content-Length': s } }) { console.log(`size is ${s}`); } when ({ status: 404 }) { console.log('JSON not found'); } when ({ status }) if (status >= 400) { throw new RequestError(res); } };
```js function todoApp(state = initialState, action) { return match (action) { when ({ type: 'set-visibility-filter', payload: visFilter }) { ({ ...state, visFilter }); } when ({ type: 'add-todo', payload: text }) { ({ ...state, todos: [...state.todos, { text, completed: false }] }); } when ({ type: 'toggle-todo', payload: index }) { const newTodos = state.todos.map((todo, i) => { return i !== index ? todo : { ...todo, completed: !todo.completed }; });
({ ...state, todos: newTodos, }); } else { state } // ignore unknown actions
} } ```
jsx <Fetch url={API_URL}> {props => match (props) { when ({ loading }) { <Loading />; } when ({ error }) { <Error error={error} />; } when ({ data }) { <Page data={data} />; } }} </Fetch>
Tags
Annotators
URL
-
-
hackmd.io hackmd.io
Tags
Annotators
URL
-
-
docs.google.com docs.google.com
- Dec 2022
-
Tags
Annotators
URL
-
-
peps.python.org peps.python.org
Tags
Annotators
URL
-
-
peps.python.org peps.python.org
Tags
Annotators
URL
-
- Sep 2022
-
developer.mozilla.org developer.mozilla.org
- May 2022
-
tc39.es tc39.es
Tags
Annotators
URL
-
- Mar 2022
-
Tags
Annotators
URL
-
-
wicg.github.io wicg.github.io
-
The URLPattern API provides a web platform primitive for matching URLs based on a convenient pattern syntax.
Tags
Annotators
URL
-
- Aug 2021
-
-
# And standalone like a case:Qo.match(people.first, Qo.m(age: 10..19) { |person| "#{person.name} is a teen that's #{person.age} years old" }, Qo.m(:*) { |person| "#{person.name} is #{person.age} years old" })
-
# How about some "right-hand assignment" pattern matchingname_longer_than_three = -> person { person.name.size > 3 }people_with_truncated_names = people.map(&Qo.match_fn( Qo.m(name_longer_than_three) { |person| Person.new(person.name[0..2], person.age) }, Qo.m(:*) # Identity function, catch-all))
-
- Jul 2021
-
github.com github.com
Tags
Annotators
URL
-
-
www.toptal.com www.toptal.com
-
In the examples above, the number 42 on the left hand side isn’t a variable that is being assigned. It is a value to check that the same element in that particular index matches that of the right hand side.
-