Here are commons ways to reuse logic in Elixir:
1a. Move Function to other module (guards, pattern-matching) 1b. Protocol - Polymorphism
- Behaviour Dynamic-func - with def method_name(implemetation, args)
defmodule FlattenArray do | |
@doc """ | |
Accept a list and return the list flattened without nil values. | |
## Examples | |
iex> FlattenArray.flatten([1, [2], 3, nil]) | |
[1,2,3] | |
iex> FlattenArray.flatten([nil, nil]) |
brew update
brew install asdf [email protected]
EDITOR=nano brew edit wxmac # Edit the file according to wxmac.patch
brew install wxmac --build-from-source
asdf plugin add erlang
asdf plugin add elixir
package main | |
import ( | |
"bytes" | |
"encoding" | |
"encoding/binary" | |
"io" | |
"fmt" | |
"stockbit.com/proto/ouch42" |
module slice | |
func InterfaceSlice(slice interface{}) []interface{} { | |
switch slice := slice.(type) { | |
case []string: | |
new := make([]interface{}, len(slice)) | |
for i, v := range slice { | |
new[i] = v | |
} | |
return new |
let decimals = 4; | |
const regexpDecimals = new RegExp(`^\\d*\\.{0,1}\\d{0,${decimals}}$`); | |
const SignupSchema = Yup.object().shape({ | |
decimal: Yup.number().test( | |
'is-decimal', | |
'too many decimals', | |
value => (value + "").match(regexpDecimals), | |
), | |
}); |
// See: https://github.com/maticnetwork/matic.js/blob/master/examples/POS-client/config.js | |
const posRootChainManager = '0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74'; | |
const posERC20Predicate = '0xdD6596F2029e6233DEFfaCa316e6A95217d4Dc34'; | |
const accounts = useAccounts(); | |
const userAddress = accounts?.[0] | |
const rootDaiContract = useContractContext(DAIDummyContext, 0); | |
const { send: approve } = useContractFunc(rootDaiContract, "approve"); |